run-time error 3075 - help

  • Thread starter Thread starter cmarsh
  • Start date Start date
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

********************************
 
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.
 
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.
 
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 & "'")
 
Back
Top