Can anyone look at the code and help me figure out what's wrong with it? This seems to be a very standard code but somehow it is not working properly. The code is suppose to shutdown the database after >3 incorrect attempts at login. However, it doesn't do that. Also, I was able to close the form and bypass the whole login process. Please help!
Code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.Combo2) Or Me.Combo2 = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.Combo2.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.Text4) Or Me.Text4 = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Text4.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
If Me.Text4.Value = DLookup("Password", "Employee", _
"[EmployeeID]=" & Me.Combo2.Value) Then
EmployeeID = Me.Combo2.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "LogOn", acSaveNo
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Text4.SetFocus
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 admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Private Sub Combo2_AfterUpdate()
'After selecting user name set focus to password field
Me.Text4.SetFocus
End Sub