I know there are a million posts on here about login forms, which is where I got most of the code for mine. I have a combo box for all of the UserNames in my database. The user names are derived from a Query (Security_Q). They are made by default as the First initial, Last name of the employee.
The problem I have is, if I change a password for an employee, that password works for any given username. For example, if my password is 'ABC', and employee can use their login, and use ABC as a password, and it works. I have attached the code below.
Hopefully someone has a solution for me. This has been driving me crazy over the last week. Thanks a lot everyone!
Private Sub Login_Click()
Dim strFilter As String, strAdmin As String
Call Employee.SetFocus
If IsNull(Me.Employee) Then
MsgBox "Please enter Username and Password", vbCritical, "Login Error"
Exit Sub
End If
Call Password.SetFocus
If IsNull(Me.Password) Then
MsgBox "Please enter Username and Password", vbCritical, "Login Error"
Exit Sub
End If
strFilter = "(([Employee]='%U') AND ([Password]='%P'))"
strFilter = Replace(strFilter, "%U", Me.Employee)
strFilter = Replace(strFilter, "%P", Me.Password)
strAdmin = Nz(DLookup("[ID]", "[Security_Q]", strFilter), "Fail")
If strAdmin = "Fail" Then
MsgBox "Incorrect Username or Password"
Else
DoCmd.Close
DoCmd.OpenForm ("ASSIST")
End If
End Sub