Solved Error 3159 Bookmark not Valid (1 Viewer)

BusyBeeBiker

New member
Local time
Today, 05:30
Joined
Jun 27, 2021
Messages
26
1. I have a form frmPersonnel which logs persons name address etc.
2. On that form I have a new record button which brings up new record based upon click event below:

DIM strBookMark as variant - Set at top of form module frmPersonnel so available to all sub procedures in module.

Private Sub cmbAddNew_Click()

If Forms!frmLoginScreen!numSecurityLevel >= 8 Then ' Checks Security Clearance
strBookMark = Me.Bookmark 'Set Bookmark for current record
Call addNewRecord("frmPersonnel", "fkTitleID") ' Add New Record Function
Me!frmStatusSubForm.Form.AllowAdditions = True ' Set Allow Additions Default Setting.
' Me.fkTitleID = ""
Me.fkTitleID.SetFocus
Call modTracking(Me.Name, 1, Environ("ComputerName"), Environ("UserName"), "") ' Tracks Addition of Record to WLP System.
End If

ExitHere: ' Any Clean Up Code
Err.Clear
Exit Sub

End Sub


3. What I want to do is when user is asked to whether to save New Record or Abandon it, on abandonment of record, I want it to return to the previous record selected , to which end I have used the code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

' Dimension Variables
Dim Response, strMessage As String

If Me.Dirty = True Then ' Validates if Record is Dirty.
If Me.NewRecord = True Then ' Validates if New Record

' Validate that Surname has Entered is a NEW record.
If IsNull(txtSurname) Then

' Initialise Message String.
strMessage = "Cannot Save Record Without Surname." & vbCrLf _
& "Select YES to return to Surname Field." & vbCrLf _
& "Select NO to Abandon Change(s). Return to Previous Record."

Response = MsgBox(strMessage, vbYesNo)

If Response = vbNo Then
Cancel = True
Me.Bookmark = strBookMark
Me.Requery
Me.txtSearch.SetFocus
GoTo ExitHere:

Else
Me.txtSurname.SetFocus
GoTo ExitHere:
End If
End If

' Asks User to Save Record or Not!
Response = MsgBox("Save New Record?", vbYesNo)
If Response = vbNo Then
Cancel = True
End If
End If
End If

ExitHere: ' Any Clean Up Code
Err.Clear

End Sub

4. I have used bookmarking to try to elicit this response (In Green) but on third line of this green coding get the error message
"Error 3159 Not a valid bookmark"

When I check strBookMark doesn't have a value as it says Empty. but a populated it first with strBookMark = Me.Bookmark 'Set Bookmark for current record.

Been trying for 2 days to resolve this issue and getting nowhere fast.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:30
Joined
May 7, 2009
Messages
13,784
you do have an Identity field (autonumber or PK field)?
you can use that instead of bookmark.

strBookmark = me!ID

to go back to previous "bookmark"

me.recordset.findfirst "ID = " & strBookmark
 

BusyBeeBiker

New member
Local time
Today, 05:30
Joined
Jun 27, 2021
Messages
26
Sorry as they say in the circus good try but no coconut!

I have amended the code as you suggested now getting the message "error 3426 - this action is cancelled by associated object"
 

moke123

AWF VIP
Local time
Today, 00:30
Joined
Jan 11, 2013
Messages
2,531
strBookMark = Me.Bookmark 'Set Bookmark for current record.
Bookmark is a property of the recordset not of the form. You could try Me.Recordset.BookMark.

You can check if a recordset is bookmarkable with Me.Recordset.BookMarkable which returns true or false.
 

jdraw

Super Moderator
Staff member
Local time
Today, 00:30
Joined
Jan 23, 2006
Messages
13,839
@BusyBeeBiker

Unrelated to the issue per se, but for consideration.

This does not do what you expect:
Code:
Dim Response, strMessage As String

This will Dim as follows:
Response as Variant
strMessage As String

Access requires explicit Dim:
Dim Response as String, strMessage As String OR
Dim Response as String
Dim strMessage As String


More info on Bookmark/Form.Bookmark
 

bastanu

AWF VIP
Local time
Yesterday, 21:30
Joined
Apr 13, 2010
Messages
862
I think moke123 gave you the answer, but here is it from MS:

In the first sub you need to set it to the form's recordset:
Code:
If Forms!frmLoginScreen!numSecurityLevel >= 8 Then ' Checks Security Clearance
strBookMark = Me.Recordset.Bookmark 'Set Bookmark for current record
Call addNewRecord("frmPersonnel", "fkTitleID") ' Add New Record Function

Cheers,
 

BusyBeeBiker

New member
Local time
Today, 05:30
Joined
Jun 27, 2021
Messages
26
Many thanks for all your comments.

In the end went down a slightly different pathway instead of using BookMarking I used Docmd.applyfilter instead to return to the previous record.

However I still kept on getting error 2501 on the DoCmd.ApplyFilter, that is till I restructured the code as follows (In Green):

It needed the inclusion of Me.Undo, without it DoCmd.ApplyFilter kicked out Error 2501.

Does anyone know why, I know it works but why?

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If glbHandleErrors Then On Error GoTo ErrHandler ' Set Error Handling

Dim strMessage As String, Response
    If Me.NewRecord = True Then ' Validates if New Record
    ' Validate that Surname has Entered is a NEW record.
        If IsNull(txtSurname) Then
        
        ' Initialise Message String.
            strMessage = "Cannot Save Record Without Surname." & vbCrLf _
                       & "Select YES to return to Surname Field." & vbCrLf _
                       & "Select NO to Abandon Change(s). Return to Previous Record."
        
           Response = MsgBox(strMessage, vbYesNo)
            If Response = vbNo Then
               Cancel = True
               Me.Undo
               DoCmd.ApplyFilter , "[pkPersonID]=" & IIf(IsEmpty(strBookMark), Forms!frmLoginscreen!fkID, strBookMark)
               Me.txtSearch.SetFocus
               GoTo ExitHere:

            Else
                Me.txtSurname.SetFocus
                GoTo ExitHere:
            End If
        End If
    
    ' Asks User to Save Record or Not!
            Response = MsgBox("Save New Record?", vbYesNo)
            If Response = vbNo Then
               Cancel = True
               Me.Undo
            End If
    End If

ExitHere:   ' Any Clean Up Code
   Err.Clear
   Exit Sub
 
ErrHandler: ' ERROR HANDLING ROUTINE.
   If Err.Number <> 0 Then
       Call LogError(Err.Number, Err.Description, Forms!frmLoginscreen!fkID, Environ("UserName"), Environ("ComputerName"), "", glbHandleErrors)
      Resume ExitHere
   End If
End Sub
 

moke123

AWF VIP
Local time
Today, 00:30
Joined
Jan 11, 2013
Messages
2,531
You can still use bookmark, just a little differently.

Something like:

Code:
    Dim rs As DAO.Recordset
    
    Set rs = Me.RecordsetClone

    rs.FindFirst "pkPersonID = " &  strBookMark ' The pkPersonID you saved

    If Not rs.NoMatch Then
        Me.Bookmark = rs.Bookmark
    End If
 

NauticalGent

CopyPaster of the First Order
Local time
Today, 00:30
Joined
Apr 27, 2015
Messages
4,067
Gasman
New to posting on forums. What the chuffing hell are code tags?
With Code Tags:
Code:
If Forms!frmLoginScreen!numSecurityLevel >= 8 Then ' Checks Security Clearance
strBookMark = Me.Recordset.Bookmark 'Set Bookmark for current record
Call addNewRecord("frmPersonnel", "fkTitleID") ' Add New Record Function

Without:
If Forms!frmLoginScreen!numSecurityLevel >= 8 Then ' Checks Security Clearance
strBookMark = Me.Recordset.Bookmark 'Set Bookmark for current record
Call addNewRecord("frmPersonnel", "fkTitleID") ' Add New Record Function
 

BusyBeeBiker

New member
Local time
Today, 05:30
Joined
Jun 27, 2021
Messages
26
Picking up on this post, I have sorted on the Bookmarking problem, many thanks for helping me understand this subject area and have marked as solved.
 

BusyBeeBiker

New member
Local time
Today, 05:30
Joined
Jun 27, 2021
Messages
26
Broadly speaking, I was using DoCmd.ApplyFilter as a way of selecting the record I wanted in the underlying table for the main form, not realising by doing so I was restricting the recordset to 1 record.

The results of which were when I tried to use Bookmarking there was only one record to bookmark.

Once that point had been forced into my grey matter the rest was relatively straight forward based upon peoples suggestions in the thread.

Again many thanks for peoples input.
 

Users who are viewing this thread

Top Bottom