Button with password not working

weilerdo

Registered User.
Local time
Today, 18:13
Joined
Apr 21, 2005
Messages
109
I have a form with a text field and a command button. My code works for the password part but it is not checking for the 3 times and exit code. I'm not real up oon coding and not sure what Im missing Any help would be appreciated:

Private Sub cmdLogin_Click()

If txtPassword = "Test" Then
DoCmd.RunMacro "Mac_man_main"
Else: MsgBox ("Please Renter Correct Password"), vbOKOnly, "Error!", 0, 0
Exit Sub
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
 
Each time the sub is executed, your variables are reset. So unless you have intLogonAttempts set as static or defined as a global, it will always be zero going into the sub.
Is it setup as static or global?
 
I beleive it is set at static, If I take the Else: MsgBox ("Please Renter Correct Password"), vbOKOnly, "Error!", 0, 0 out of the top then the lower part works and after 3 attempts it gives the message and exits. If I leave the top part in all it does it give the Msg box and never looks at the 3 attempts.
 

Users who are viewing this thread

Back
Top Bottom