Article ID: 131385
Article Last Modified on 10/10/2006
Sub Returning_Field_Headers_Example()
Dim db As database
Dim rs As Recordset
Dim vaTmp() As String
Dim vaNew As Variant
Dim dbLocation As String
' Opens the database and creates a record set
' dbLocation could be any directory where the Access files are
' stored.
dbLocation = "c:\access\sampapps\nwind.mdb"
' In version 97 use the sample file northwind.mdb usually located
' in c:\program files\microsoft office\office\samples\northwind.mdb
Set db = DBEngine.Workspaces(0).OpenDatabase(dbLocation)
Set rs = db.OpenRecordset("Orders")
' This section fills in the field names from the Orders table.
ReDim vaTmp(rs.Fields.Count)
For x = 0 To rs.Fields.Count - 1
vaTmp(x + 1) = rs.Fields(x).Name
Next
Sheets("Sheet1").Cells(1, 1).Resize(1, rs.Fields.Count) = vaTmp
' Retrieves the data to the sheet. The sheet should be called
' "Sheet1"
numberOfRows = Sheets("Sheet1").Cells(2, 1).CopyFromRecordset(rs)
Sheets("Sheet1").Activate
End Sub
copyfr
Additional query words: XL
Keywords: kbdtacode kbhowto kbprogramming KB131385