The Fields Collection Object
Every Recordset object contains a collection of fields represented by the Fields collection object. Within the Fields collection object, there is a collection of Field objects, each representing a column in the recordset. Through the Fields collection object, each individual Field object can be accessed.
Every value within one column of a recordset shares a common group of characteristics, which define that field. These characteristics for each column are stored in a corresponding Field object within the recordset’s Fields collection object.
The Field Object
In its simplest form, a Field object has a name and a value. A field’s name uniquely identifies a column within the recordset. The name of a given field can be accessed through Field object’s Name property, for example:
Dim fld As Field
rst.Open "Authors", _
"DSN=BiblioDSN"
Set fld = rst.Fields(1)
Debug.Print fld.Name
rst.Close
Set fld = NothingThe value of a Field object changes depending on which record the record pointer is pointing to. The value of a field can be obtained by the Value property of the Field object:
Debug.Print rst.Fields!Author.Value Debug.Print rst.Fields!Author
Both of these statements would print the same value, because the two lines are identical in meaning: because the Value property is the default property for the Field object.
When you add new records to a recordset, you can use the Value property to set the value for a particular field in the new record:
rst.AddNew rst.Fields("Author").Value ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access