PDA

View Full Version : BookMark Problem



BusyBeeBiker
07-03-2021, 03:12 PM
28697

strBoomark is set in the declaration section of frmPersonnel above so is available through-out this class module.
Private strBookmark as Variant

1. On clicking on Add Record button I am trying to save the bookmark of the current record just prior to adding a new record (Highlighted Blue), so that if I abandon the new record, I can go back to the previous record.



Private Sub cmbAddNew_Click()If glbHandleErrors Then On Error GoTo ErrHandler ' Set Error Handling
Dim dbs As DAO.Database ' Dimension Database
Dim rs As DAO.Recordset ' Dimesion Recordset
Set dbs = CurrentDb
Set rs = Me.RecordsetClone

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

ExitHere: ' Any Clean Up Code
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
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

2. After the New Record opens, I then want to offer the user the option of either saving the New Record or Abandoning it in the Form_BeforeUpdate Event below:

3. On abandonment I want to return to the previous record(in Blue), but it's not working because strBookMark = Empty



Private Sub Form_BeforeUpdate(Cancel As Integer)
If glbHandleErrors Then On Error GoTo ErrHandler ' Set Error Handling
Dim dbs As DAO.Database ' Dimension Database
Dim rs As DAO.Recordset ' Dimesion Recordset

Set dbs = CurrentDb
Set rs = Me.RecordsetClone

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 ' Cancel Record Save/Update
rs.Bookmark = strBookMark
Me.txtSearch.SetFocus
GoTo ExitHere:


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

End If


ExitHere: ' Any Clean Up Code
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
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


Can anybody tell me what I'm doing wrong, strBookMark is Empty and it seems that after Cancel = True the form is not pointing at any record in the table.

Been trying for about a week to resolve this issue, can anyone give me an idea of what to do!!

SamT
07-04-2021, 08:18 AM
Assuming that the code compiles, RecordSetClone is empty or not set.

Have you already ran a query or opened a Record or otherwise set the Form's RecordSource Property?

BTW, the VBAX editor shrinks all Images, making them illegible. Better to Attach a *.jpg file using the Go Advanced button

Gasman
07-05-2021, 07:48 AM
Crossposted and solution/woklaround found before even posting here?

https://www.access-programmers.co.uk/forums/threads/error-3159-bookmark-not-valid.318458/

BusyBeeBiker
07-05-2021, 02:28 PM
Gasman
Unfortunately the problem popped it head up again.

SamT insight proved useful currently working through the code, hitting a few more problems which I am trying to resolve, before asking the Brains Trust to contribute.

Proving to be a particularly frustrating problem.

Gasman
07-06-2021, 12:45 AM
If people do not use bookmarks, they save the PK of the record and then use FindFirst to locate it agan.?

Regardless, it is appreciated if you advise members of any crossposting, so they do not waste their time repeating what has already been offered.?

This applies to most forums, and crossposting without mentioning it, tends to reduce the number of members who will assist.

BusyBeeBiker
07-06-2021, 01:19 AM
Will do, with regards to bookmarking, the problem I had originally was due to the fact that I was using Docmd.Applyfilter as my method of locating a record in the underlying table.

However this had the consequence of restricting the underlying recordset to 1 record, which caused problems when I tried to Cancel a new record and return to the previous record.

I am currently working through this problem, if I don't sort it out, I will pick up this thread shortly asking for guidance.

Gasman
07-06-2021, 01:49 AM
So use that FindFirst option I mentioned to locate your record?