Index Property (Field Object)
Index Property (Field Object)
The Index property returns the index number of the Field object within the Fields collection. Read-only.
Syntax
objField.Index
Data Type
Long
Remarks
The Index property indicates this object's position within the parent Fields collection. It can be saved and used later with the collection's Item property to reselect the same field in the collection.
The first object in the collection has an Index value of 1.
An index value should not be considered a static value that remains constant for the duration of a session. It can be affected when other fields are added and deleted. The index value is changed following an update to the object to which the Fields collection belongs.
Example
This code fragment shows the Fields collection's Count property and the Index property working together:
' set up a variable as an index to access a small collection
' fragment from the functions Fields_FirstItem, Fields_NextItem
If objFieldsColl Is Nothing Then
MsgBox "must first select a Fields collection"
Exit Function
End If
If 0 = objFieldsColl.Count Then
MsgBox "No fields in the collection"
Exit Function
End If
' Fragment from Fields_FirstItem
iFieldsCollIndex = 1
Set objOneField = objFieldsColl.Item(iFieldsCollIndex)
' verify that the Field object is valid ...
' Fragment from Fields_NextItem
If iFieldsCollIndex >= objFieldsColl.Count Then
iFieldsCollIndex = objFieldsColl.Count
MsgBox "Already at end of Fields collection"
Exit Function
End If
iFieldsCollIndex = iFieldsCollIndex + 1
Set objOneField = objFieldsColl.Item(iFieldsCollIndex)
' verify that the Field object is valid, then loop back ...