Private Sub ButLogin_Click()
Dim strFormLogin As String
Dim strFormPassword As String
Dim strSQL As String
Dim strFormName As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
strFormLogin = Nz(Me.txtUserName, " ")
strFormPassword = Nz(Me.txtPassword, 0)
strFormName = "frmMainmenu"
strSQL = "SELECT UserNameID, Name, Password,Admin,statusid,isuser " & _
"FROM tblUsers " & _
"WHERE Name = '" & Forms!frmLogin!txtUserName & "' "
Set rs = CurrentDb.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then
gintLoginAttempts = gintLoginAttempts + 1
If gintLoginAttempts = 3 Then
MsgBox "You have had 3 unsuccessful login attempts " & vbCr & vbCr _
& "The application will now close.", vbCritical, "Failed Login"
DoCmd.Close
Exit Sub
End If
MsgBox "Your Login name is not recognised", vbExclamation, "Unknown User Name"
Me.txtUserName = ""
Me.txtUserName.SetFocus
Me.ButExit.Default = False
Exit Sub
End If
If Not rs!IsUser Then
MsgBox "Your UserName (" & rs!Name & ") has been made inactive. " & vbCr & vbCr & "Contact the System Administrator." & vbCr & vbCr & "The system will now close down.", vbCritical, "Inactive User"
DoCmd.Close
Exit Sub
End If
If rs!Password = strFormPassword Then
gstrUserName = rs!Name
gintUserID = rs!UserNameID
gblnAdmin = rs!Admin
gintStatus = rs!StatusID
Set rs2 = CurrentDb.OpenRecordset("tblLogins", dbOpenDynaset)
With rs2
.AddNew
!UserNameID = gintUserID
!Timein = Now()
!Status = "In"
.Update
End With
DoCmd.Close
DoCmd.OpenForm strFormName
Else
ggintLoginAttempts = ggintLoginAttempts + 1
If ggintLoginAttempts = 3 Then
MsgBox "You have had 3 unsuccessful login attempts " & vbCr & vbCr _
& "The application will now close.", vbCritical, "Failed Login"
DoCmd.Close
Exit Sub
End If
MsgBox "You entered and incorrect password", vbExclamation, "Incorrect Password"
Me.txtPassword = ""
Me.txtPassword.SetFocus
Exit Sub
End If
rs.Close
rs2.Close
End Sub