Error 3159 not a valid bookmark (3 Viewers)

ClaraBarton

Registered User.
Local time
Yesterday, 22:49
Joined
Oct 14, 2019
Messages
577
Code:
Private Sub Form_Click()
      Dim bm As Variant
      Dim rs As Recordset
10    Set rs = Me.Parent.RecordsetClone
      'save the bookmark
20    bm = Me.Bookmark
30    With rs
40        .FindFirst "InvoiceID =" & Me.InvoiceID
50            If Not .NoMatch Then
60            Me.Parent.Bookmark = rs.Bookmark
70            End If
80    End With
      'reinstate the bookmark
90    Me.Bookmark = bm
100   Set rs = Nothing
End Sub
I got this code from Arnelgp and it does exactly what I wanted (stopped the jumping back to first record on selection). HOWEVER... When the form is first open I get Error 3159 not a valid bookmark on line 90. If I just press end and move on it works but not when the form is first open. I first thought it was because I was jumping to the sub subform from the master form and perhaps there wasn't a valid recordset. But this code is on the sub subform so it surely has the Parent recordset. Why isn't a valid bookmark set?
 
There must be more to it than what you're showing. You said the problem only happens when you first open the form, but the code you're showing only gets executed when you click on the form. So, when the form opens, this code shouldn't run yet. Are you calling this code in the Open event or something?
 
No, I mean when I click on it after opening the form. When I'm working on various things on the form, move to other records, etc. it works fine. If I click there first, before doing anything else. it errors.
 
You may just have to add some error handling to deal with it then.
 
If you can do so, put a breakpoint on line 90. When it breaks, you can use the cursor to hover over a variable to see what it contains. The trick is to see what "bm" contains.

Your DIM of BM says it is a Variant. That's OK, but a Variant is a data type that can be null. Therefore, it would be good to verify that "bm" actually contains something other than null. You really don't care WHAT it contains as long as it ISN'T null, and the mouse-hover trick would tell you that much right away. Going the other direction (line 20), you are dumping something into a Variant, which almost can't fail. At line 90, diddling with Me.Bookmark would implicitly perform a navigation to the bookmark. You could also set the breakpoint on line 20 and hover over "bm" there. Either way, the question will be "what is in 'bm' by line 90?"
 
Kind of a lot of unnecessary code. I think this does the exact same thing you are trying to do.
Code:
Private Sub Form_Click()
    dim ChildID as long
    ChildID= me.SomePK   ' I assume the child record has a PK different than the invoice ID
    Me.Parent.recordset.FindFirst "InvoiceID =" & me.invoiceID
   ' I assume by moving the parent it moved the child because the records are linked
    me.recordset.findfirst "some child pK = " & childID
End Sub

The bookmark becomes invalid any time the recordset is requeried.

Not sure I understand what you are doing here.
Me.Bookmark = bm

If you have to move back on the child form then that is because the parent and child are linked. If that is the case then you requeried the child and thus the error. So save the PK of the child record and forget the bookmarks.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom