Hi folks, I have been trying to figure this out for hours and I cannot seem to find my error. It is a basic login vba that I have put together from looking at examples here and other places.
I used the dlookup to find the UserName, Password, and Password Checkbox values in the lutWSCStaff table. It should, should being the operative word, store those values into the variables and then run the comparisons below.
The problem I have is that it is defaulting to "Incorrect username" when the correct usernames are in the login box. (txtLogin on the form).
I am sure it is probably something very small I am missing, but I cannot seem to track down where the error is occurring.
I used the dlookup to find the UserName, Password, and Password Checkbox values in the lutWSCStaff table. It should, should being the operative word, store those values into the variables and then run the comparisons below.
The problem I have is that it is defaulting to "Incorrect username" when the correct usernames are in the login box. (txtLogin on the form).
I am sure it is probably something very small I am missing, but I cannot seem to track down where the error is occurring.
Code:
Private Sub btnLogin_Click()
Dim logVar As Variant
Dim passVar As Variant
Dim pwdVar As Variant
'dlookups for password rest, login, and password
logVar = DLookup("UserName", "lutWSCStaff", "txtLogin = '" & txtLogin() & "'")
pwdVar = DLookup("Password", "lutWSCStaff", "txtPassword = '" & txtPassword() & "'")
passVar = DLookup("ResetPassword", "lutWSCStaff", "ResetPassword = -1")
'Checks that Username and password are not empty
If IsNull(Me.txtLogin) Or IsNull(Me.txtPassword) Then
MsgBox "You Must Enter a Username AND Password!", vbCritical
Me.txtLogin.SetFocus
'determines if the username is correct
Else
If (logVar <> txtLogin.Value) Then
MsgBox "Invalid User Name. Please Re-Enter Your User Name."
Me.txtLogin = Null
Me.txtLogin.SetFocus
'determines if password is correct
Else
If (logVar = txtLogin.Value) Then
If (pwdVar <> txtPassword) Then
MsgBox "password incorrect"
Me.txtPassword = Null
Me.txtPassword.SetFocus
'determines if password should be reset
Else
If (passVar = -1) Then
MsgBox "please reset password"
'DoCmd.OpenForm "frmPasswordChange", , , "[UserName] = " & Me.txtLogin
Else
If (pwdVar = txtPassword) Then
Me.Visible = False
MsgBox "login successful"
End If
End If
End If
End If
End If
End If
End Sub