Help with Password validation.....Data type mismatch

ecu97wedge4

New member
Local time
Today, 12:43
Joined
Aug 13, 2013
Messages
3
Help with Password and Username match
HELP please....I have gotten to the bitter end of this but cannot get this run smooth.... I know this problem is within the DLookUp line.

In my tblMember I do have a column with ID....I just cant get the DLookup to match the username and password then OPEN the navigation screen.
So here is the code

How do I get it to recognize the name in cboMember and then recognize the 4digits in txtPassword as a match from tblMember or qryPassword....then if they do match open the form frmNavigation.
If they DONT match then reply with MsgBox and statement saying Invalid.

The query called qryPassword pulls Member and Password if this would be helpful.

Right now it is saying Run time error '3464':
Data type mismatch in criteria expression.

I looked to see if all boxes were set to TEXT and they were.
SO PLEASE HELP....HELP...HELP

Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboMember) Or Me.cboMember = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboMember.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 tblMember to see if this
'matches value chosen in combo box
If Me.txtPassword.Value = DLookup("Password", "tblMembers", "ID =" & Me.cboMember.Value) Then

'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "frmNavigation"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

End Sub
 
Hello ecu97wedge4, Welcome to AWF.. :)

What is the RowSource of the ComboBox? Why are you using a Query here? Which line is the Data Type Mismatch Error thrown?

I know you are new to this Forum, but from next post; Please use Code Tags when posting VBA Code.
 
Thanks for the reply pr2-eugin...i need the help.

As for the ROW Source...I went to the box and copied this from ROW SOURCE
SELECT [tblMember].[ID], [tblMember].[Member] FROM tblMember ORDER BY [Member];

Query was created to Get the Member Name and Password in same result. Not using yet.

The data type mismatch is in the highlighted row....if I understand your question correctly.

I will repost the code with tags now....

Code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
    If IsNull(Me.cboMember) Or Me.cboMember = "" Then
      MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.cboMember.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 tblMember to see if this
    'matches value chosen in combo box
    If Me.txtPassword.Value = DLookup("Password", "tblMember", "ID =" & Me.cboMember.Value) Then
             
        'Close logon form and open splash screen
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNavigation"
    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If

End Sub
 
I cannot see the hihlighted section, but anyway your code seems to be fine.. Except for DLookUp whichc could be wrapped in Nz, to avoid Null.. However it shoudl not be a problem.. Also you do not need the .Value property.. Me.<controlName> is all that you need..
Code:
Private Sub cmdLogin_Click()
    [COLOR=SeaGreen]'Check to see if data is entered into the UserName combo box[/COLOR]
    If IsNull(Me.cboMember) Or Me.cboMember = "" Then
        MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.cboMember.SetFocus
        Exit Sub
    End If
    
    [COLOR=SeaGreen]'Check to see if data is entered into the password box[/COLOR]
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
        MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.txtPassword.SetFocus
        Exit Sub
    End If
    
    [COLOR=SeaGreen]'Check value of password in tblMember to see if this
    'matches value chosen in combo box[/COLOR]
    If Me.txtPassword = [COLOR=Red][B]Nz([/B][/COLOR]DLookup("Password", "tblMember", "ID =" & Me.cboMember), [COLOR=Red][B]"N/A")[/B][/COLOR] Then
        'Close logon form and open splash screen
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNavigation"
    Else
        MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
End Sub
Other than that, there is only one two other possibility for the Error..

1. ID being type Text, if that is the case.. then DLookUp should be..
Code:
DLookup("Password", "tblMember", "ID = [COLOR=Red][B]'[/B][/COLOR]" & Me.cboMember & "[COLOR=Red][B]'[/B][/COLOR]")
2. The ComboBox properties might be messed up.. Make sure the Bound Column is 1, Column count is 2, Column widths is 0cm;3cm.

See if some of the above suggestions help..
 
Just curious if this will work... try the following code (you will need to change your field names) and then use an if statement to check the value of "pass"

Code:
Dim pass As String
pass = Nz(DLookup("Password", "tblEmployees", "tblEmployees.Password = txtPassword AND tblEmployees.ID = cboEmployee.Value"), "na")
 

Users who are viewing this thread

Back
Top Bottom