views:

656

answers:

3

Hi Guys I have a question on checkboxes in acess 2003

I have 4 checkboxes on my form and one of these boxes, i want to restrict so only users supplied with the correct password eg (report1) can check that box. I have a small textbox to the side of the checkbox labelled manager password.

I am not sure how to set this validation in access. I have right-clicked on the check box, gone to properties and seen the validation rule but not sure where to go from there. I have an idea of what my VB code will be if applicable and I am including that if it helps

Code Snippet If txtpassword.text = "report1" then closedsftleader.yes = true else msgbox.show "Management Password is incorrect, please try again"

END IF

Not even sure if this code would work but its an idea. Please help when you can. Thank you.

+1  A: 

You want to add an event on the text box (I believe it's the "changed" event) and then enable/disable the textbox based on the contents of the text box.

As a side note, this is an odd design for protecting contents of a form. You may want to consider forcing users to log in to your Access app.

brien
Thanks for the info Brien. I understand the nature of this very odd design but this is the first department wide database i am working on and a lot of things are quite new to me. User logins will later on be incorporated into the database as time goes on. Again..Thaank you
TT1611
I would say you'd use the AfterUpdate event. While with a checkbox, the OnChange event will only fire once, it's not a good event to use for any other controls, because for a textbox, for instance, it fires for each character typed. That there is no difference for a checkbox isn't sufficient reason to use OnChange instead of AfterUpdate.
David-W-Fenton
+1  A: 

You can handle the OnClick event of the checkbox and not allow a change if the textbox doesn't have the correct password.

toast
Again, OnClick is the wrong event. You don't care about the click, you care about the control being UPDATED. Thus, AfterUpdate is the right event. OnClick is useful when you want to check whether it's a right click, shift-click, ctrl-click, etc., so you can do different things depending on the type of click.
David-W-Fenton
+1  A: 

Have you considered locking or disabling this particular checkbox? For example:

Private Sub Form_Current()
    Me.closedsftleader.Enabled = (Me.txtpassword = "Report1")
End Sub

Private Sub txtpassword_AfterUpdate()
    Me.closedsftleader.Enabled = (Me.txtpassword = "Report1")
End Sub

Disabling like this is simple for your user to understand, rather that a checkbox that seems impossible to click, furthermore, it will be easy enough to change this to refer to a global variable or user name.

I generally set tag properties for controls, which allows me to hide or enable controls in batches, according to the user and / or password.

Remou
my code was very similar to this and almost what i ended up doing. A snippet is belowIf Me.txtpassword.Value = "Report1" Then Me.closedcftLeader.Locked = FalseElse MsgBox ("Please Enter correct password") Me.txtpassword.SetFocus Me.closedcftLeader.Locked = TrueEnd IfEnd Sub
TT1611