By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Access 2003: Locking Forms

ebs57
P: 18
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:

Expand|Select|Wrap|Line Numbers
  1.   If inStr = "password" Then
  2.       With Form
  3.         .AllowEdits = false
  4.         .AllowAdditions = false
  5.         .AllowDelections = false
  6.       End With
  7.   Else
  8.      ... turn everything back on ...
  9.   End If
  10.  
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:

Expand|Select|Wrap|Line Numbers
  1.   txtBox52.Enabled = False
  2.   txtBox52.Locked = True
  3.  
...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...thanks in advance.
May 9 '07 #1
Share this Question
Share on Google+
5 Replies


Denburt
Expert 100+
P: 1,356
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.
May 9 '07 #2

Denburt
Expert 100+
P: 1,356
Also your variable could be dropping it's value, where are you declaring that or are you?
May 9 '07 #3

ebs57
P: 18
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.
May 10 '07 #4

Denburt
Expert 100+
P: 1,356
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.
May 10 '07 #5

ebs57
P: 18
Will do, and thanks for suggestions.
May 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.