Referencing sequencial fields of a table in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with many fields which was imported in from excel. It has 36
months across the table. I need to reformat this into one field with the 36
months of data in one field. Each of the 36 months contains man power levels.

I normally reference a field i.e. T![Field1]. But in this case, I would
like reference it numerically so that I can start from a certain field and
take the next 11 fields and remap it. This way the VBA code can be
generalized.

Any suggestions???


Thanks,

Gary
 
You can reference the members of a recordset's Fields collection using
either the name of the field, or the numeric ordinal number of the field.
Here's an example ...

Public Sub WalkFields()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim lngField As Long

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM Employees")
For lngField = 0 To rst.Fields.Count - 1
Debug.Print rst.Fields(lngField).Value
Next lngField
rst.Close

End Sub
 
Back
Top