Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2007
    Posts
    214

    Question Unanswered: Edit record in a form question

    Hi All,

    Is there a code for a command button to make my record fields on my form be "locked" until I click the button? Basically, when my users enter data in the fields on the form, I want the fields to be locked until they click the "unlock" button. This will enable accidental errors such as overtyping data on a record they didn't want to edit.

    For instance, right now, you can just go to any record on my form and begin entering/changing data in the text and combo box fields. I just want all the records to be "locked" until the user clicks the "unlock" command button that I would place on the form. Thanks for any help or code that might make this happen.

  2. #2
    Join Date
    Aug 2006
    Posts
    559
    Why don't you just make it so that IF there is data in the field on the form, then the field is disabled or locked for editing?

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    place some code behind the button which enables or locks the code

    I forget the details but its somehting like enabled or locked

    me.form.enabled = not me.form.enabled

    you may instead need to set each control, as the above code will probably lock all controls including the command button. the not bit says set the value of the control to the opposite of its current setting.

    so you may have to set each control

    eg
    mycontrol1.enabled = not mycontrol1.enabled
    mycontrol2.enabled = not mycontrol2.enabled
    mycontrol3.enabled = not mycontrol3.enabled
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Oct 2007
    Posts
    214
    Quote Originally Posted by Grafixx01
    Why don't you just make it so that IF there is data in the field on the form, then the field is disabled or locked for editing?

    I would still need to come back to the data to edit it at a later time.

  5. #5
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by benz1984
    I would still need to come back to the data to edit it at a later time.
    Then you may be able to add a "On Double-Click" event, have the user enter a password to unlock the field (control) you want to edit and then once the user enters the correct password, it'll let them in to change / update the information. Then when they save the record, it locks it again.

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    IF you are after a locking system for the fields, the way I do it is pretty simple:

    Toggle button: togLock

    Form's On Current code: Me.togLock = False : Me.AllowEdits = False

    togLock AfterUpdate code: Me.AllowEdits = Not Me.TogLock
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Oct 2007
    Posts
    214
    Well, I did as above and all my fields are locked, but when I push the toggle button, nothing happens and they remain locked. Any ideas how to get it to unlock them when I push the button? THanks!

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Bah, that's right, it has to be a command button or the object is locked too.

    Command Button: cmdLock

    Form's On Current code: Me.AllowEdits = False : Me.cmdLock.Caption = "Unlock"

    cmdLock Click code:
    Code:
        Me.AllowEdits = Not Me.AllowEdits
        If Me.AllowEdits = True Then
            Me.cmdLock.Caption = "Lock"
        Else
            Me.cmdLock.Caption = "Unlock"
        End If
    Apologies for any confusion
    Last edited by StarTrekker; 09-16-08 at 02:15.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Oct 2007
    Posts
    214

    Unhappy

    Still nothing when I click the button. When I click the button records remain locked. Maybe I am missing something?

  10. #10
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Talking

    Quote Originally Posted by benz1984
    Well, I did as above and all my fields are locked, but when I push the toggle button, nothing happens and they remain locked. Any ideas how to get it to unlock them when I push the button? THanks!

    Hi benz,

    On my form I have it to open and set to not allow any edits until you click the Edit button. Here is the code behind it:

    Code:
    Me.AllowEdits = True    'Makes the form temporarily Editable.
        Me.cEmail.Enabled = True  'Only this field.
        Me.Email.Enabled = True    'And this one.
        Me.Web.Enabled = True    'And finally this one too.
        FirstName.SetFocus
        
        Me.lblEditMode.Visible = True  'Edit Mode reminder.
    After I have made changes and all, I click on my SAVE commandbutton and coded it to : Me.AllowEdits = False

    As you can see in the Me.AllowEdits, I have set only certain fields to be edited, not all of them. I also have a reminder that you are in Edit Mode until you save it, then it goes away.

    hope this helps some
    have a nice one,
    BUD

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Post 8 corrected. There was a copy/paste error... the first two lines of code were duplicated. Should work now
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Oct 2007
    Posts
    214
    Hi All,

    Thanks a bunch for your help. Here's what worked for me.

    in the form on current event i entered: Me.AllowEdits = False

    and in my cmd button click event i entered: Me.AllowEdits = True

    This seems to be working great. Simple it seems, but it locks all my records in my database (9k! records) and when I pick the record I want to edit, then click my "unlock" command button, it allows me to edit that record. Once I navigate to a different record it locks everything again which is what I wanted. I basically didn't want users to be able to easily type over data entries by mistake and this seems to eliminate that problem.


  13. #13
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Good stuff
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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