I need help with this code that i am trying to use for login attempts. After i enter an invalid password it will not increment any further. The value for failed login attempts stays static. If anyone can help me with this it would be much appreciated i have been stuck on this for hours.
Code:
Option Compare Database
Private Sub Login_Button_Click()
Dim User, GetPass, Pass As String
Dim Count, FailedAttempts As Integer
Pass = Me.PasswordEntry_TextBox
User = Me.UserNameEntry_TextBox
GetPass = DLookup("UserPass", "UserList", "[UserName]='" & User & "'")
Count = 2
FailedAttempts = 1
If (StrComp(Pass, GetPass, vbBinaryCompare) = 0) Then
If MsgBox("Login was Successful. You will be redirected to the homepage after you click ok.", vbInformation, "Login Success") = vbOK Then
DoCmd.OpenForm ("User_Homepage")
DoCmd.Close acForm, "LoginPage", acSaveNo
Exit Sub
End If
Else
If (FailedAttempts = 3) Then
If MsgBox("You have Exceeded the number of Login Attempts. Your account will now be locked. Reset your password using the Reset button on the login page or contact your system administrator.", vbInformation, "Account Locked") = vbOK Then
'tbd
Exit Sub
End If
Else
If MsgBox("The Password you have entered is incorrect you have " & Count & " of 3 attempts left.", vbInformation, "Failed Login Attempt " & FailedAttempts & " of 3") = vbOK Then
FailedAttempts = FailedAttempts + 1
Count = Count - 1
End If
End If
End If
End Sub