Results 1 to 9 of 9
  1. #1
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194

    For the life of me I can't find the right record lock code.

    I've been searching and thinking to no avail on how to lock specific records from editing and require a passcode to unlock them. I have a form that data is entered onto in order to create a record. Usual stuff right? I want a button that locks just the record being worked on and requires a passcode to unlock. "Help me obi-wan-Kenobi you're my only hope."



    I'd like to lock the current record from tbl_MBR from frm_ViewMBR with a button, be able to close the form and re-open it to a record that's still locked.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You can set the AllowEdits (and deletions, etc) in the current event, and then toggle it behind your button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    is there a code in the record to determine this?
    normally set the form to ALLOWEDITS= FALSE
    user clicks a button to unlock, enter the code.
    Now you can either hardcode the passcode in vb (not great) , or put the passcode in a table then check it (better) so it can be changed on the fly.

    Code:
    sub btnUnlock_click()
    dim vRet 
    
       vRet = InputBox("Enter edit code","Authorized only")
       me.ALLOWEDITS = IsValidUnlockCode(vRet)
    end sub
    
      'when user changes records
    sub form_OnCurrent()
    me.ALLOWEDITS=false
    end sub
    
    
    function IsValidUnlockCode(byval pvCode)
    dim vCorrectCode
    
    vCorrectCode =Dlookup("[passcode]","tPassword")
    IsValidUnlockCode=vCorrectCode = pvCode 
    if vCorrectCode <> pvCode then msgbox "Incorrect code"
    end function

  4. #4
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194
    I can lock the controls immediately, but when I re-open the form (with that record), all controls are unlocked again. I'm trying to figure out what I'm doing wrong. Thanks ranman for the instruction on how to add a passcode!

    I want the form to open allowing edits, unless it is the locked record. Is that possible?
    Last edited by lccrews; 01-02-2018 at 01:48 PM. Reason: Added clarity.

  5. #5
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194
    I solved my problem by adding a field to my table. Then by adding this code to the Form's current event, it worked!
    Code:
    Private Sub Form_Current()
    If Me.Locked = Yes Then
    Me.AllowEdits = False
    End If
    End Sub
    Last edited by lccrews; 01-02-2018 at 02:58 PM. Reason: Found solution

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    Put your code in the Form_current event instead of the form_load event.
    Form_current will look at the currently displayed record to decide whether to lock or not.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    This must not have been clear enough?

    Quote Originally Posted by pbaldy View Post
    You can set the AllowEdits (and deletions, etc) in the current event, and then toggle it behind your button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194
    Quote Originally Posted by pbaldy View Post
    This must not have been clear enough?
    No I was confused by "toggle it". Oy... You gave me the answer and I totally missed it. Thanks Paul. You're a master. I'm just a little dense sometimes.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No worries, I'm a lot dense sometimes.

    By toggle I just meant change it, like setting the value one way in the current event and the other way behind your button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Record lock question
    By NikoTheBowHunter in forum Access
    Replies: 3
    Last Post: 05-24-2017, 12:04 PM
  2. Replies: 6
    Last Post: 03-17-2017, 01:30 PM
  3. Replies: 5
    Last Post: 03-21-2015, 01:42 PM
  4. Replies: 9
    Last Post: 05-12-2012, 12:16 PM
  5. lock a record
    By Nokia N93 in forum Programming
    Replies: 3
    Last Post: 02-21-2011, 02:51 PM

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
  •  
Other Forums: Microsoft Office Forums