Databases Reference
In-Depth Information
If you delete the last remaining record in a recordset, then BOF and EOF remain
False until you attempt to change the current position.
16.3.1.2 Notes on the Move methods
If you use MovePrevious when the first record is current, the BOF property is set
to True , and there is no current record. A further MovePrevious will produce an
error, and BOF remains True .
If you use MoveNext when the last record is current, the EOF property is set to
True , and there is no current record. A further MoveNext will produce an error,
and EOF remains True .
If the recordset is a table-type recordset, then movement follows the current
index, which is set using the Index property of the Recordset object. If no index is
set (or if the recordset is not table-type), the order of returned records is not
predictable.
The most common use of the Move methods is to cycle through each record in a recordset.
Example 16-2 illustrates this. It creates both a table-type and a dynaset-type recordset on
BOOKS and prints (in the debug window) a list of PubIDs and Titles. Note the use of the:
Do While Not rs.EOF
statement, which is typical of this type of procedure. Also, note the presence of this line:
rsTable.MoveNext
within the Do loop. It is a common error to forget to advance the current record pointer, in
which case the PC will enter an endless loop, in this case printing the same line over and
over again!
Example 16-2. Moving through a Recordset
Sub exaRecordsetMove( )
Dim db As DATABASE
Dim rsTable As Recordset
Dim rsDyna As Recordset
Set db = CurrentDb
Set rsTable = db.OpenRecordset("Books")
Debug.Print "Books indexed by PubID/Title:"
' Move through table-type recordset using PubTitle index
rsTable.INDEX = "PubTitle"
rsTable.MoveFirst
Do While Not rsTable.EOF
Debug.Print rsTable!PubID & " / " & rsTable!Title
rsTable.MoveNext
Loop
Search WWH ::




Custom Search