Cycle though fields of a recordset

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

What is the code to cycle through the fields of a recordset starting at the
second field through the last field when the index of the last field is not
expliciyly known?

Thanks for all help!

Steve
 
Your looking for Fields.Count

For lngX = 1 to rs.Fields.Count -1
' do stuff ...
Next

The fields collection is a zero based collection.
Therefore
Field 2 is at index 1
Field n is at index (.Count -1)

Terry
 
This example uses a loop counter so you can start where you wish:

Function CycleFields()
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim i As Integer

Set rs = DBEngine(0)(0).OpenRecordset("SELECT * FROM MyTable;")
For i = 0 To rs.Fields.Count - 1
Set fld = rs.Fields(i)
Debug.Print fld.Name, fld.Type
Next
Set fld = Nothing
rs.Close

Set rs = Nothing
End Function
 
Allen,

Thanks for taking the time to provide the whole code. As always,I appreciate
your help!

Steve
 
Back
Top