Private Sub cmdLogin_Click()
Dim PassRS As Recordset
Static PassCount As Integer
'Initialize count to 0
PassCount = 0
Set PassRS = Db.OpenRecordset("Login")
While Not PassRS.EOF And Not LoginOK
If (PassRS.Fields("password").Value = txtPassword.Text) And (PassRS.Fields("Username").Value = cboLogin.Text) Then
LoginOK = True
CurrentUser = PassRS("Username").Value
Else
PassRS.MoveNext
End If
Wend
If LoginOK Then
Beep
frmIntro.Show
frmPassword.Hide
txtPassword = ""
LoginOK = False
mdiMain.lblLoginTime.Caption = Format$(Now, "H:MM AMPM")
mdiMain.lblUsername.Caption = CurrentUser
mdiMain.timDisplay.Enabled = True
mdiMain.mnuLogoff.Caption = "Log off " & CurrentUser
Else
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
PassCount = PassCount + 1
MsgBox PassCount
If Response = vbRetry Then
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
'Add 1 to Counter
'PassCount = PassCount + 1
'When Counter exceeds 3 show Msgbox
If PassCount = 3 Then
MsgBox "Three invalid login attempts... this program will now shut down", vbInformation, "Program shutdown"
End
End If
ElseIf Response = vbCancel Then
Unload frmPassword
End
End If
End If
End Sub