Navigating a Recordset

Moving around in a recordset is one of the most basic actions. There are many ways you can move within a recordset, but the basic concept for each technique is the same.

Regardless of where or how you want to move around in a recordset, there is always a place pointed to by a record pointer.

The Record Pointer

The record pointer indicates the current record. Imagine a record pointer as the needle on a record player. It points to the current song so that you can access that song’s information. In a recordset, a record pointer points to a record (most of the time) so that you can access that record’s information.

Two important properties of a Recordset object, which have appeared in previous examples without full explanation, are the BOF (Beginning Of File) and EOF (End Of File) properties. These are Boolean properties that indicate that you have stepped out of the bounds of the recordset. Figure 5-6 shows you that the BOF property is True when the record pointer is before the first record in the recordset and that the BOF property is True when the record pointer is past the last record in the recordset.

A typical recordset with BOF and EOF Properties
Figure 5-6. A typical recordset with BOF and EOF Properties

If, when you open a recordset, there are no records in that recordset, both the BOF and EOF properties are set to True. We can check for this situation with the following code:

If (Not (rst.BOF And rst.EOF)) ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.