ADO Item property
Indicates a specific member of a collection, by
name or ordinal number. For example, it returns a specified item in the
fields collection.
Example:
itemfields =
rec.Fields.Item(1)
or
itemfields =
rec.Fields.Item("Name")
Note:
Use the Item property to return a
specific object in a collection. If Item cannot find an object in the
collection corresponding to the Index argument, an error occurs.
Also, some collections don't support named objects; for these collections,
you must use ordinal number references.
The Item property is the default property for
all collections; therefore, the following syntax forms are interchangeable:
collection.Item (Index)
collection (Index)
The Item property applies to: |
Axes
Collection (ADO MD) |
Columns
Collection (ADOX) |
CubeDefs
Collection (ADO MD) |
Dimensions Collection (ADO MD) |
Errors
Collection (ADO) |
Fields
Collection (ADO) |
Groups
Collection (ADOX) |
Hierarchies Collection (ADO MD) |
Indexes
Collection (ADOX) |
Keys
Collection (ADOX) |
Levels
Collection (ADO MD) |
Members
Collection (ADO MD) |
Parameters Collection (ADO) |
Positions Collection (ADO MD) |
Procedures Collection (ADOX) |
Properties Collection (ADO) |
Tables
Collection (ADOX) |
Users
Collection (ADOX) |
Views
Collection (ADOX) |
|
|
Example:
Dim cnn As
ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim fld As ADODB.Field
Dim i As Integer, j As Integer
Dim limit As Long
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandText = "SELECT * FROM Customers WHERE Country = 'Germany'"
' open recordset
rst.Open cmd, , adOpenStatic, adLockReadOnly
' Connection and
CommandType are omitted because a Command object is provided
limit = rst.Fields.Count - 1
i = 1
Do While Not rst.EOF
'rs.EOF and rs.BOF returns
True when rs is empty.
For j = 0 To limit
Set fld = rst.Fields.Item(j)
Debug.Print fld.Value
Next j
i = i + 1
rst.MoveNext
Loop
' clean up objects
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing