When is a Bookmark created ? (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 12:19
Joined
Sep 21, 2011
Messages
14,223
Hi all,
Not played around with bookmarks much, but wanted to use it to get back to a record after a requery on the form.

My code for the Requery button is

Code:
Private Sub cmdRequery_Click()
    Dim lngId As Long
    Dim rst As DAO.Recordset
    Dim strCriteria As String
    Dim varBookMark As Variant
    
    ' Save record so requery on subform will pick up all last record written
    If Me.Dirty Then Me.Dirty = False
    lngId = Me.ID
    varBookMark = Me.Bookmark
    Me.Requery
    strCriteria = "ID=" & lngId
    'Set rst = Me.sfrmEmails.Form.Recordset

    ' Requery the subform
    'Me.sfrmEmails.Form.Requery
    ' Go back to record we were on
    Me.Recordset.FindFirst strCriteria
    ' Now the sub form
    'rst.FindFirst strCriteria
    'Set rst = Nothing
    'DoCmd.RunCommand acCmdRecordsGoToLast
    DoCmd.RunCommand acCmdRecordsGoToLast
    DoCmd.GoToRecord acDataForm, Me.Name, acPrevious, 5 ' Needed for a continuous form as only last record shows.
    'DoCmd.RunCommand acCmdRecordsGoToLast
    Me.Bookmark = varBookMark

End Sub

I had just added a new record and then pressed the Requery button. The code works fine if I have not added a record. This is the first time I have added a record since amending the code.?

I expected the Me.Dirty to save the record, but both Me.BookMark and varBookMark have ? when printed in the immediate window?

What do I need to check for when having added new record(s) please?

The error is 3159 Not a valid bookmark, which I accept a ? would not be.

TIA
 

Users who are viewing this thread

Top Bottom