Greetings wise ones
I have a small problem figuring out how to include the “3 strikes and you’re out” code within my login form. I did get a start by using some code that I found in this forum (I can’t recall the name of the author, thanks to him/her in any case). However, is doesn’t seem to work. Went the punter puts in the wrong password for the 4th time, the application is supposed to close – but is doesn’t. Any help will be greatly appreciated. The code is as follows:
Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer
strUser = Me.txtUser
If DCount("[Password]", "Staff", "[UserID]='" & Me.txtUser & "'") > 0 Then
strPWD = DLookup("[Password]", "Staff", "[UserID]='" & Me.txtUser & "'")
If strPWD = Me.txtPwd Then
intUSL = DLookup("[AccessLevel]", "Staff", "[UserID]='" & Me.txtUser & "'")
Select Case intUSL
Case 1
DoCmd.OpenForm "Home", acNormal
Case 2
DoCmd.OpenForm "Home", acNormal, , , acFormReadOnly
Case 3
MsgBox "Not configured yet", vbExclamation, "Not configured"
Case 4
MsgBox "Not configured yet", vbExclamation, "Not configured"
End Select
DoCmd.Close acForm, "Login Dialog", acSaveNo
Else
If MsgBox("You entered an incorrect password" & vbCrLf & _
"Would you like to re-end your password?", vbQuestion + vbYesNo, "Restricted Access") = vbYes Then
Me.txtPwd.Value = ""
Counter = Counter + 1
If Counter = 3 Then
MsgBox "You have entered an incorrect password too many times. This database will now close!", vbCritical, "Wrong password!"
DoCmd.Quit
End If
Else
DoCmd.Quit
End If
End If
End If
End Sub
I have a small problem figuring out how to include the “3 strikes and you’re out” code within my login form. I did get a start by using some code that I found in this forum (I can’t recall the name of the author, thanks to him/her in any case). However, is doesn’t seem to work. Went the punter puts in the wrong password for the 4th time, the application is supposed to close – but is doesn’t. Any help will be greatly appreciated. The code is as follows:
Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer
strUser = Me.txtUser
If DCount("[Password]", "Staff", "[UserID]='" & Me.txtUser & "'") > 0 Then
strPWD = DLookup("[Password]", "Staff", "[UserID]='" & Me.txtUser & "'")
If strPWD = Me.txtPwd Then
intUSL = DLookup("[AccessLevel]", "Staff", "[UserID]='" & Me.txtUser & "'")
Select Case intUSL
Case 1
DoCmd.OpenForm "Home", acNormal
Case 2
DoCmd.OpenForm "Home", acNormal, , , acFormReadOnly
Case 3
MsgBox "Not configured yet", vbExclamation, "Not configured"
Case 4
MsgBox "Not configured yet", vbExclamation, "Not configured"
End Select
DoCmd.Close acForm, "Login Dialog", acSaveNo
Else
If MsgBox("You entered an incorrect password" & vbCrLf & _
"Would you like to re-end your password?", vbQuestion + vbYesNo, "Restricted Access") = vbYes Then
Me.txtPwd.Value = ""
Counter = Counter + 1
If Counter = 3 Then
MsgBox "You have entered an incorrect password too many times. This database will now close!", vbCritical, "Wrong password!"
DoCmd.Quit
End If
Else
DoCmd.Quit
End If
End If
End If
End Sub