Code not working right

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. If I take out the Else Msg box in the top section the 3 times works. But I dont get a message that I did a wrong password. If I leave the top msg in it never runs the lower part of this code. I'm not real up on 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
 
That should be:
Code:
Private Sub cmdLogin_Click()

If txtPassword = "Test" Then
    DoCmd.RunMacro "Mac_man_main"
Else
    MsgBox ("Please Renter Correct Password"), vbOKOnly, "Error!", 0, 0
    '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
    Else
        Exit Sub
    End If
End If

End Sub
 
alternativly:-

Code:
Private Sub cmdLogin_Click()
Static intLogonAttempts As Integer
intLogonAttempts = intLogonAttempts + 1
If txtPassword = "Test" Then
    DoCmd.RunMacro "Mac_man_main"
    intLogonAttempts = 0
    Exit Sub
'If User Enters incorrect password 3 times database will shutdown
ElseIf intLogonAttempts > 2 Then
    MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
    Application.Quit
Else
    MsgBox ("Please Renter Correct Password"), vbOKOnly, "Error!", 0, 0
End If
'intLogonAttempts = 0
End Sub

Peter
 

Users who are viewing this thread

Back
Top Bottom