Search code examples
formsms-accessnavigationms-access-97

Navigate programmatically through the records of a continuous form


I would like to navigate through the records of a continuous form in Access 97. I don't find how to do it. This is what I tried:

Me.RecordSetClone.MoveFirst moves to the first record logically, but not in the UI. Also the CurrentRecord property does not change.

I cannot set the CurrentRecord property, it is readonly. Me.CurrentRecord = 1 gives an error.

DoCmd.GoToRecord Record:=acFirst seems to have no effect.

What is the correct way to move to the first record in a continuous form (and to the next/previous)?


Solution

  • Use the Bookmark property of RecordsetClone and Form.

    Caveat: I'm pretty sure all this worked in Access 97, but that was a really long time ago.

    Sub DemoNavigate()
    
        Dim RS As DAO.Recordset
    
        Set RS = Me.RecordsetClone
        RS.MoveFirst
        ' or
        RS.AbsolutePosition = 0
    
        ' Navigate in form
        Me.Bookmark = RS.Bookmark
    
        ' next record
        RS.MoveNext
        ' or
        RS.AbsolutePosition = 1
    
        Me.Bookmark = RS.Bookmark
    
        ' Move to searched record
        RS.FindFirst "someField = 42"
        Me.Bookmark = RS.Bookmark
    
    End Sub