Odd DLookup Error: 13 - Type Mismatch?

Heatshiver

Registered User.
Local time
Tomorrow, 00:29
Joined
Dec 23, 2011
Messages
263
I have two fields on a form, UserID and Password. A person types in the UserID and Password and clicks a button to go to the next form. The button performs a DLookup function to check whether or not the UserID and Password exist in tblUserID.

The fields for both of these are text in the table. If I use a UserID that is made up of numbers everything checks out fine and I continue on to the next form. However, if I use something with text I then get the Error 13 mismatch...

Here is my code:

If DLookup("[UserID]", "[tblUserID]", "[UserID]= '" & Me.UserID & "' And [Password]= '" & Me.Password & "'") Then
MsgBox "Valid User ID and Password."
Else
MsgBox "Invalid User ID and/or Password."
Exit Sub
End If


This had worked before when I had used text as I had a UserID named "AMD", this would then allow certain buttons to become visible on the next form. But now it just gives me an error each time. The Password is made up of both text and numbers and seems fine. Where is the mismatch?

I even tried CStr around the form field in the criteria with no luck...

Thanks for the help.
 
It would be because you are evaluating the Dlookup() as TRUE/FALSE which it can not return. Use Dcount() > 0 EG

If DCount("[UserID]", "[tblUserID]", "[UserID]= '" & Me.UserID & "' And [Password]= '" & Me.Password & "'") > 0 Then
 
Thank you! Worked perfectly!
 

Users who are viewing this thread

Back
Top Bottom