The Fields Collection
Take a lookin in the help system (while in the modules) so you get VBA help. There is a section with the title above. Here is part of it...
The Fields Collection
The Fields collection is one of ADO's intrinsic collections. A collection is an ordered set of items that can be referred to as a unit. For more information about ADO collections, see The ADO Object Model in Chapter 1.
The Fields collection contains a Field object for every field (column) in the Recordset. Like all ADO collections, it has Count and Item properties, as well as Append and Refresh methods. It also has CancelUpdate, Delete, Resync, and Update methods, which are not available to other ADO collections.
Examining the Fields Collection
Consider the Fields collection of the sample Recordset introduced in this chapter. The sample Recordset was derived from the SQL statement
SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID = 7
Thus, you should find that the Recordset Fields collection contains three fields.
'BeginWalkFields
Dim objFields As ADODB.Fields
objRs.Open strSQL, strConnStr, adOpenForwardOnly, adLockReadOnly, adCmdText
Set objFields = objRs.Fields
For intLoop = 0 To (objFields.Count - 1)
Debug.Print objFields.Item(intLoop).Name
Next
'EndWalkFields
This code simply determines the number of Field objects in the Fields collection using the Count property and loops through the collection, returning the value of the Name property for each Field object. You can use many more Field properties to get information about a field. For more information about querying a Field, see The Field Object.