|
6#
楼主 |
发表于 2004-4-1 03:52:00
|
只看该作者
老话一句——自己动手丰衣足食
琢磨两天还是自己搞定,代码如下,大家可参考:
Dim xls As New Excel.Application, wkb As Excel.Workbook, wks As Excel.Worksheet
Dim rst As New ADODB.Recordset
Dim intRow As Integer, strSQL As String
Set wkb = xls.Workbooks.Add
Set wks = xls.ActiveSheet
strSQL = Me!frmChildForm.Form.RecordSource
rst.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
wks.Cells(1, 1).Value = rst.Fields(0).Name
wks.Cells(1, 2).Value = rst.Fields(1).Name
wks.Cells(1, 3).Value = rst.Fields(2).Name
intRow = 2
Debug.Print rst.RecordCount
Do Until rst.EOF
wks.Cells(intRow, 1).Value = rst.Fields(0).Value
wks.Cells(intRow, 2).Value = rst.Fields(1).Value
wks.Cells(intRow, 3).Value = rst.Fields(2).Value
rst.MoveNext
intRow = intRow + 1
Loop
xls.Visible = True
rst.Close
Set rst = Nothing
最烦的是微软已将其DAO淘汰,在XP版中FORM返回的还是DAO记录集,不是ADODB记录集,所以代码了多两句
不知道在2003版中怎样(还没用过2003) |
|