Simple Password Help

G

Greg Staley

I am putting a simple password protection in a command button's OnClick.
Here is what I have.... It brings up the box, but if you put anything in the
box, or cancel, it opens the form anyway. Can someone help me figure out
why it is not working?

Greg
The Oft Access Confused

Private Sub cmdOpenAdminMenu_Click()

On Error GoTo Err_cmdOpenAdminMenu_Click
Dim sPassword As String
Const sAccess = "password"
sPassword = InputBox("Please enter the password now", "Login")
If sPassword <> sAccess Then
Cancel = True
End If
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmAdmin"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenAdminMenu_Click:


Exit Sub
 
J

Joe Fallon

Setting Cancel=True is not doing anything when used in the Sub Procedure for
the button.
It is only useful when actually trying to open a form.
You can Cancel the form open event by setting Cancel=True.

So your code simply continues on and executes the open form command.

If you replace Cancel=True with a MsgBox telling the user there is an error
and then add an Exit Sub it will skip over the rest of the code whenever
there is a mismatch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Password protecting a form 1
Hiding typed text 1
Hiding text for passwords 1
A2000 form ceases working under A2002 1
Input box question 2
Password locking a Form 3
filter on combo box possible? 1
If, Then, Else 3

Top