Article ID: 146405
Article Last Modified on 8/17/2005
Public Function Test()
Dim xl As Object
Dim db As Database
Dim rs As Recordset
Dim r As Integer, c As Integer
Dim TempArray() As Variant
'Create a new object for Microsoft Excel.
Set xl = CreateObject("excel.application.5")
'Set the database object and create the recordset for the Customer
'table in the directory
'c:\program files\common files\microsoft shared\msquery.
Set db = OpenDatabase("C:\Program Files\Common Files\" & _
"Microsoft Shared\Msquery", False, False, "dbase IV;")
Set rs = db.OpenRecordset("Customer")
'Start a new workbook.
xl.workbooks.Add
'Create an array where # rows = # records and # columns = # fields
'in the recordset.
ReDim TempArray(1 To rs.RecordCount, 1 To rs.Fields.Count)
'Place the contents of the recordset into the array TempArray
'and replace any nulls in the recordset with "Empty."
For r = 1 To rs.RecordCount
For c = 1 To rs.Fields.Count
If IsNull(rs(c - 1)) Then
TempArray(r, c) = Empty
Else
TempArray(r, c) = rs(c - 1)
End If
Next
rs.MoveNext
Next
'Dump the contents of TempArray onto the active worksheet.
xl.activesheet.range("a1").Resize(rs.RecordCount, _
rs.Fields.Count).Value = TempArray
Set xl = Nothing
End Function
Keywords: kbbug kbfix KB146405