Share via


DAO Recordset: Recordset Navigation

OverviewHow Do IFAQSampleODBC Driver List

This article explains how to move (scroll) from record to record in a recordset. It also tells you where to find more information about other recordset navigation mechanisms, such as , , and bookmarks.

Topics covered include:

  • Scrolling in DAO recordsets

  • Other navigation techniques

For more information, see the topic "Positioning the Current Record Pointer with DAO" in DAO Help.

Scrolling in DAO Recordsets

Recordsets provide several member functions you can use to scroll or move from one record to the next, previous, first, or last record, or move n records relative to the current position. You can also test whether you have scrolled beyond the first or the last record.

To determine whether scrolling is possible in your recordset, call the member function of class .

To scroll in DAO

  • Forward one record: call the member function.

  • Backward one record: call the member function.

  • To the first record in the recordset: call the member function.

  • To the last record in the recordset: call the member function.

  • N records relative to the current position: call the member function. Specify the value of N, negative (for previous records) or positive (for later records), in your call.

To test for the end or the beginning of the recordset in DAO

  • Have you scrolled past the last record? Call the member function.

  • Have you scrolled past the first record (moving backward)? Call the member function.

For example, the following code uses IsBOF and IsEOF to detect the limits of a recordset as the code scrolls through it in both directions.

// Open a snapshot; first record is current
CEnrollmentSet rsEnrollmentSet( NULL );
rsEnrollmentSet.Open( );

// Deal with empty recordset
if( rsEnrollmentSet.IsEOF( ) )
    return FALSE;

// Scroll to the end of the snapshot
while ( !rsEnrollmentSet.IsEOF( ) )
    rsEnrollmentSet.MoveNext( );

// Past last record, so no record is current
// Move to the last record
rsEnrollmentSet.MoveLast( );

// Scroll to beginning of the snapshot
while( !rsEnrollmentSet.IsBOF( ) )
    rsEnrollmentSet.MovePrev( );

// Past first record, so no record is current
rsEnrollmentSet.MoveFirst( );
// First record (if any) is current again

returns a nonzero value if the recordset is positioned past the last record. returns a nonzero value if the recordset is positioned before the first record. In either case, there is no current record to operate on. If you call when IsBOF is already true, or call when IsEOF is already true, the framework throws a .

****Tip   ****In the general case, where records may be deleted by you or by other users (other recordsets), check that both IsEOF and IsBOF return a nonzero value to detect an empty recordset.

Other Navigation Techniques

Besides scrolling, discussed in Scrolling in DAO Recordsets, class supplies five other ways to navigate to a particular record or to a particular place in a recordset, as shown in the following table.

Ways to Navigate in an MFC DAO Recordset

CDaoRecordset Member Function For more information...
See Using Seek in the article DAO Recordset: Seeking and Finding
See Using Find in the article DAO Recordset: Seeking and Finding
See Bookmarks in MFC DAO in the article DAO Recordset: Bookmarks and Record Positions
See Absolute and Percent Positions in MFC in the article DAO Recordset: Bookmarks and Record Positions
See Absolute and Percent Positions in MFC in the article DAO Recordset: Bookmarks and Record Positions

See Also   DAO: Where Is..., DAO Recordset, DAO Recordset: Seeking and Finding, DAO Recordset: Bookmarks and Record Positions