dim iRow, iCol as integer
dim strLine, strData as stringwith MSFlexGrid
for irow=0 to .rows-1
strLine = ""
.row = iRow
for icol=0 to .cols-1
.col = iCol
strLine = strLine & .text & vbTab
next icol
strline = left(strline,len(strline)-1) & vbNewline
strData = strData & strline
next irow
open "C:\record.txt" for output as #1
print #1,strData
close #1
dim strLine, strData as stringwith MSFlexGrid
for irow=0 to .rows-1
strLine = ""
.row = iRow
for icol=0 to .cols-1
.col = iCol
strLine = strLine & .text & vbTab
next icol
strline = left(strline,len(strline)-1) & vbNewline
strData = strData & strline
next irow
open "C:\record.txt" for output as #1
print #1,strData
close #1
按照你的代码带是生成了txt文件可是文件里面的字段名和自段内容对不奇啊:(
能不能改进呢?
怎样将记录集快速导出到Excel:
'***************************
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
' Open the recordset.
Set db = DBEngine.Workspaces(0). _
OpenDatabase("D:\db1.mdb")
Set rs = db.OpenRecordset("SELECT _
* FROM MyTable")
' Open the destination Excel workbook.
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks. _
Open("D:\Book1.xls")
' This is all it takes to copy the contents
' of the recordset into the first worksheet
' of Book1.xls.
xlBook.Worksheets(1).Range("A1"). _
'*******************
CopyFromRecordset rs
'*******************
' Clean up everything.
xlBook.Save
xlBook.Close False
xlApp.Quit
rs.Close
db.Close
Set xlBook = Nothing
Set xlApp = Nothing
Set rs = Nothing
Set db = Nothing
Dim xlApp As Excel.Application
Dim xlApp As Excel.Application
我是有什么没有定义哪?]
Private Sub Command1_Click()
Dim I As Long, J As Long, K As Long
Dim PrintString As String
For I = 0 To Data1.Recordset.RecordCount - 1
If K = DBGrid1.VisibleRows Then
DBGrid1.Scroll 0, DBGrid1.VisibleRows
K = 0
End If
For J = 0 To DBGrid1.Columns.Count - 1
PrintString = PrintString &
DBGrid1.Columns(J).CellText(DBGrid1.RowBook(K)) & "/"
Next
Printer.Print PrintString
PrintString = ""
K = K + 1
DoEvents
Next
End SubPrivate Sub Form_Activate()
Data1.Recordset.MoveLast
Data1.Recordset.MoveFirst
End Sub