Authenticate login

SeanATech

Rookie but trying
Local time
Today, 08:37
Joined
Apr 13, 2011
Messages
35
This is my code to authenticate my log ins where the code is red is where it is telling me my first error is any suggestions on how to make this work?
it says its a run error 3464 data mismatch
Option Compare Database

Private Sub cmd_Login_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboAgentLoginID) Or Me.cboAgentLoginID = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboAgentLoginID.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 Me.txtPassword.Value = DLookup("Password", "Logins", _
"[AgentLoginID]=" & Me.cboAgentLoginID.Value) Then


AgentLoginID = Me.cboAgentLoginID.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frm_Logins", acSaveNo
DoCmd.OpenForm "frm_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
 
Last edited:
Well, if user login id isn't a number (which I'm guessing it isn't) you need quotes (and I would use the NZ function to avoid a potential Invalid Use of Null error if the user doesn't exist in the table):
Code:
[COLOR=black]If Me.txtPassword.Value = [COLOR=red][B]Nz([/B][/COLOR]DLookup("Password", "Logins", _
"[AgentLoginID]=" [COLOR=red][B]& Chr(34)[/B][/COLOR] & Me.cboAgentLoginID[B][COLOR=red] & Chr(34)[/COLOR][/B])[B][COLOR=#ff0000], vbNullString)[/COLOR][/B] Then[/COLOR]
[COLOR=#ff0000]
[/COLOR]
 
Thank you bob that is twice you have saved me from throwing my computer out a window today. if you have any examples of how I could create a Login session for my agents that would be extremely helpful thats about all I have left to create and I have no idea of how to create the login session. I tried someone elses example and I could never get it to save the date/time of login. If you would be interested in viewing my db and offering some of your expertise please let me know. I am extremely grateful to people like you willing to offer help to an inexperienced user.
 

Users who are viewing this thread

Back
Top Bottom