Hello All,
I am having an odd problem with my login form for my database. If I select a username and input the correct password it gives me a password invalid message box (as it should if the password were invalid), however, if I make no changes at all to the password I entered and just press the login button again the form works correctly. For some reason it fails on the first attempt at any login, no matter if the password is correct or not. It occurs for every user.
Here is screenshot of my form (I've blacked out the name of my organization).
The drop down box is named "cboEmployee" the password text box is named "txtPassword". cboEmployee is row sourced as follows: SELECT [TMID], [Team Member Name] FROM ExtQ_TeamMembers ORDER BY [Team Member Name];
TMID is the primary key for the TeamMembers table, which is a list of employees. ExtQ_TeamMembers is just a query which combines the first and last name of the employees from the TeamMembers table for display purposes.
The login button runs the following code when clicked:
Code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
If md5(Nz(Me.txtPassword.Value, "None")) = DLookup("Password", "TeamMembers", "[TMID]=" & Me.cboEmployee.Value) Then
'Close logon form and open splash screen
DoCmd.Close acForm, "GUI_LoginDialog", acSaveNo
DoCmd.OpenForm "GUI_Home"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Again the weird thing is that on the first attempt I always receive a "Password Invalid" message despite being certain that the password entered is correct. Furthermore this doesn't happen on the second attempt, even if I leave txtPassword untouched and just re-click "Login"
Any help you could provide me with would be great appreciated. I am sure I am just missing some simple error in my code but I have been staring at it for quite a while now.
Thanks!
Paddon