Private Sub slExportInvoice(ByVal sFileN As String)
'Start by jiang 2002/10/11
On Error GoTo ErrHandler
Dim lsCaseno As String
Dim lsInvoice As String
Dim lsContainer As String
Dim myworkspace As Workspace
Dim mydatabase As DataBase
Dim mytable As Recordset
Dim iloop As Integer
Dim sFileName As String
Dim sPathN As String
Dim exlApp As Excel.Application
Dim lRow As Long
Dim lCol As Long
Dim lInvRow1 As Long
Dim lConRow1 As Long
Dim lCasRow1 As Long
Me.Enabled = False
Me.MousePointer = vbHourglass
lblts.Visible = True
lblts.Caption = "ハセンラノヨミ..."
DoEvents
Set myworkspace = Workspaces(0)
Set mydatabase = myworkspace.OpenDataBase(G_PATH_WMDB & "\" & GS_MDB_INVOICE_PRT)
Set mytable = mydatabase.OpenRecordset("select * from [invoice attached] order by invoice,conterner,[LOT CASE/MODULE NO],[PART NO]", dbOpenDynaset, dbReadOnly)
'ADO连接
public gsCn As string
gsCn=”Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=;Initial Catalog= Investment;Data Source= ServerName”
'生成 TXT文件
Public sub Qtxt(Question SQL statement as string )
Dim i As Integer
Dim j As Integer
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Dim rs As New ADODB.Recordset
rs.open Question one SQL statement,gsCn,1,1
''创建一个文件
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile ("c:\" & rs.recordcount &".txt")
Set f = fs.GetFile("c:\" & rs.recordcount &".txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
Do while not rs.eof
ts.write " " & rs.fields(“index”).value
rs.movenext
loop
rs.close
ts.Close'关闭该文件
End sub
'生成Excel文件
Public sub Qexcel(Question SQL statement as string)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'生成Excel所需的引用
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim iEx As New Excel.Application
Dim iExcel As Object
iEx.Workbooks.Add
Set iExcel = iEx.Worksheets("sheet1")
iEx.Sheets.Select 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim rs As New ADODB.Recordset
rs.open Question SQL statement as string,gsCn,1,1
Do while not rs.eof
I=1
iEx.Range("A" & i & ":G" & i).Merge ‘合并单元格
iEx.Range("A" & i).Value = rs.fields(“index”).value
Rs.movenext
Loop
Rs.close
iExcel.SaveAs "C:\" & FileName
End sub
'生成Word文件
Public sub Qword(Question SQL statement as string)
Dim wd As Object
Set wd = CreateObject ("Word.Basic")
wd.FileNewDefault
wd.FontSize 20
Dim rs As New ADODB.Recordset
Rs.open Question SQL statement,gsCn,1,1
Do while not rs.eof
wd.Insert rs(“index”).value
Rs.movenext
Loop
Rs.close
wd.FileSaveAs "C:\*.Doc"
wd.FileClose
Set wd = Nothing
End sub