Access 2003: Locking Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ebs57
    New Member
    • May 2007
    • 18

    Access 2003: Locking Forms

    I am a noob to VBA; I use it in Access 2003 to try and automate some junk in our d/b.

    Within some forms I implemented some goofy VB password code and then tried to lock the form if the password matches:

    Code:
      If inStr = "password" Then
          With Form
            .AllowEdits = false
            .AllowAdditions = false
            .AllowDelections = false
          End With
      Else
         ... turn everything back on ...
      End If
    Okay, so when I test it I can edit everything. I even went to the property sheet and manually tried turning off editing - no good. The only thing that worked programatically was setting RecordsetType = "Snapshot", but that apparently locks all my records displayed by the form and not just the one with the correct p/w.

    I would think there would be an easy way to lock all the controls in a form without having to do a For ... Next loop to disable each individual control, and I have the feeling I have to do something else first before I can disable edits or there's some Acc2K3 global setting I am not twiddling.

    By the way, in my travels I've learned that if I run this code:

    Code:
      txtBox52.Enabled = False
      txtBox52.Locked = True
    ...it won't work reliably unless I swap the .Locked and .Enabled properties. I get seemingly random results (for example, the text box will gray out when I advance to a record once but not the next two times). I did not know there was a priority to this, but I suppose it makes sense. Could this be related to my form editing errors?

    I understand I'm probably doing something wrong and I am pretty much "teaching" myself VBA via the web and by having my boss yell at me to git er done yesterday. I would sincerely appreciate any comments...than ks in advance.
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    I think your issue may be where you are placing your code. You didn't tell us that and it is very important.

    Try using the "On Current" event for that form that you want locked.

    Comment

    • Denburt
      Recognized Expert Top Contributor
      • Mar 2007
      • 1356

      #3
      Also your variable could be dropping it's value, where are you declaring that or are you?

      Comment

      • ebs57
        New Member
        • May 2007
        • 18

        #4
        Thank you for your reply.

        My code was triggered from the OnCurrent event; I did try previously moving it around to various other events with no luck. The value was derived from a textbox and I did step the debugger through several times to see what was going on (when I hovered over the string it showed the correct value and all the correct branching took place). Thing was, I could still edit the form when all was said and done.

        In the end, I declared every control and then disabled/enabled each. I thought that was a bit clumsy but it works nonetheless. My solution was total beginner and I'd rather udderstan what's going on and create more compact, efficient code.

        Comment

        • Denburt
          Recognized Expert Top Contributor
          • Mar 2007
          • 1356

          #5
          Originally posted by ebs57
          Thank you for your reply.

          My code was triggered from the OnCurrent event; I did try previously moving it around to various other events with no luck. The value was derived from a textbox and I did step the debugger through several times to see what was going on (when I hovered over the string it showed the correct value and all the correct branching took place). Thing was, I could still edit the form when all was said and done.

          In the end, I declared every control and then disabled/enabled each. I thought that was a bit clumsy but it works nonetheless. My solution was total beginner and I'd rather udderstan what's going on and create more compact, efficient code.
          I wish I could offer more help, sounds like you have it working but I have no idea why you couldn't just disable the form properties and off you go. It is good you would like to understand the code and what it is doing but something somewhere must be preventing the changes from taking effect. If there is anything else I can do let me know.

          Comment

          • ebs57
            New Member
            • May 2007
            • 18

            #6
            Will do, and thanks for suggestions.

            Comment

            Working...