How to: Move Through a DAO Recordset
Access Developer Reference |
A Recordset object usually has a current position, most often at a record. When you refer to the fields in a Recordset, you obtain values from the record at the current position, which is known as the current record. However, the current position can also be immediately before the first record in a Recordset or immediately after the last record. In certain circumstances, the current position is undefined.
You can use the following Move methods to loop through the records in a Recordset:
- The MoveFirst method moves to the first record.
- The MoveLast method moves to the last record.
- The MoveNext method moves to the next record.
- The MovePrevious method moves to the previous record.
- The Move method moves forward or backward the number of records you specify in its syntax.
You can use each of these methods on table-type, dynaset-type, and snapshot-type Recordset objects. On a forward-only-type Recordset object, you can use only the MoveNext and Move methods. If you use the Move method on a forward-only-type Recordset, the argument specifying the number of rows to move must be a positive integer.
The following example opens a Recordset object on the Employees table containing all of the records that have a Null value in the ReportsTo field. The function then updates the records to indicate that these employees are temporary employees. For each record in the Recordset, the example changes the Title and Notes fields, and saves the changes with the Update method. It uses the MoveNext method to move to the next record.
|
Note |
---|
The previous example is provided only for the purposes of illustrating the Update and MoveNext methods. It would be much faster to perform this bulk operation with a SQL UPDATE query. |