Private Sub cmdLogin_Click()
Dim bValid As Boolean
bValid = False
'Check to make sure that username and password are not blank
If Nz(Me.txtUserName, "") = "" Then
MsgBox "User Name cannot be blank."
Me.txtUserName.SetFocus
ElseIf Nz(Me.txtPassword, "") = "" Then
MsgBox "Password cannot be blank."
Me.txtPassword.SetFocus
Else
'If the username is incorrect we'll tell the user that they entered an invalid username or password
'It's generally considered an insecure practice to inform the user that they have entered a
'correct or incorrect username.
If DCount("UserName", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'") = 0 Then
MsgBox "Sorry, you entered an invalid username or password."
Else
Dim sPswdHash As String
sPswdHash = Hash(Me.txtPassword)
If DLookup("PswdHash", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'") <> sPswdHash Then
MsgBox "Sorry, you entered an invalid username or password."
Else
bValid = True
'TempVars is only available in Access 2007 and Access 2010
'Change this to use a global variable if you are using Access 2003 or older
'Global variables do not survive resets while TempVars do
'Storing the UserID is what determines if a user is logged in as well as
'which user is logged in.
TempVars.Add "UserID", DLookup("UserID", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'")
End If
End If
End If
If bValid = True Then
DoCmd.OpenForm "frmMainForm"
'Open the relevant form.
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 1 Then
'DoCmd.OpenForm "frmMainForm"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 2 Then
'DoCmd.OpenForm "Manager_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 3 Then
'DoCmd.OpenForm "Manager_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 8 Then
'DoCmd.OpenForm "User_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 9 Then
'DoCmd.OpenForm "User_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 10 Then
'DoCmd.OpenForm "CAM_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 11 Then
'DoCmd.OpenForm "Assurance_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 12 Then
'DoCmd.OpenForm "CAM_Interface_Form"
'If DLookup("GroupID", "tblUser", "UserID = '" & TempVars.UserID & "'") = 13 Then
'DoCmd.OpenForm "Assurance_Interface_Form"
'End If
'End If
'End If
'End If
'End If
'End If
'End If
'End If
'End If
'Close this form
DoCmd.Close acForm, "frmLogin"
Else
Me.txtPassword = Null
Me.txtUserName.SetFocus
End If
End Sub