I need help to figure out why my code is not working correctly. Everything works fine except that it will allow the user to > 3 attempts. According to the code, it should close the entire database but that doesn't happen. Also, it will let me close the login form and access the entire database without even having to login. Please help fix my code!
Here's my code:
Code:
Option Compare Database
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