run-time error 3075 - help

C

cmarsh

It could be because I have looked at this too long but I just can't find
what is wrong. The problem is in the DLookup statement below, where the
error shows
' [strUser] = John Doe'

Private Sub cmdlogin_Click()
'Checking if cmbuser is null
If IsNull(Me.cmbuser) Or Me.cmbuser = "" Then
MsgBox "You must enter a User Name.", vbOKOnly
Me.cmbuser.SetFocus
Exit Sub
End If
'Checking if txtpass is null
If IsNull(Me.txtpass) Or Me.txtpass = "" Then
MsgBox "You must enter a Password.", vbOKOnly
Me.txtpass.SetFocus
Exit Sub
End If
'Checking value of password

********************************
If Me.txtpass.Value = DLookup("strPassword", "tblLogin", " [strUser] = " &
Me.cmbuser.Value) Then

lnguser = Me.cmbuser.Value ' stored in module for future use

********************************
 
D

Douglas J. Steele

Since strUser is a text field, the value needs to be in quotes. The safest
is:

If Me.txtpass.Value = DLookup("strPassword", "tblLogin", " [strUser] = """ &
Me.cmbuser.Value & """") Then

That's three double quotes in front of, and four double quotes after, the
reference to the combo box.
 
K

Klatuu

If Me.txtpass.Value = DLookup("strPassword", "tblLogin", " [strUser] = " &
Me.cmbuser.Value) Then

Your naming convention is very confusing, so I am not sure this is the
problem, but if the field strUser is a text field, the syntax should be:
If Me.txtpass.Value = DLookup("strPassword", "tblLogin", " [strUser] = """
&
Me.cmbuser & """") Then

Note, the Value property is not required. It is the default value.
 
J

Jim Burke in Novi

What they said. One thing I find it easier to do is to use single quotes in
these cases - just a little bit less confusing to look at for my eyes:

DLookup("strPassword", "tblLogin", " [strUser] = '" & Me.cmbuser.Value & "'")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error 3075 Missing Operator 7
Macro to VBA 20
Run Time Error 3075 2
Choose Form that Loads Based on Login 6
Not stopping at text box 1
Password login code 12
Login Help! 2
Password at Login Form 6

Top