Simple Password Help

  • Thread starter Thread starter Greg Staley
  • Start date Start date
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
 
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.
 
Back
Top