Consulting

Results 1 to 7 of 7

Thread: BookMark Problem

  1. #1

    BookMark Problem



    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!!

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    86
    Location
    Crossposted and solution/woklaround found before even posting here?

    https://www.access-programmers.co.uk...-valid.318458/

  4. #4
    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.

  5. #5
    VBAX Regular
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    86
    Location
    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.

  6. #6
    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.

  7. #7
    VBAX Regular
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    86
    Location
    So use that FindFirst option I mentioned to locate your record?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •