2
votes

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.

3
The .Text property of an Access control is available only when the control has the focus. It's how you know in code what's been typed in the control, as opposed to what has been validated by the underlying bound field. It's generally not used except in very rare circumstances, such as in the control's OnChange event. - David-W-Fenton

3 Answers

2
votes

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.

1
votes

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.

1
votes

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