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 & "'")
 
D

Douglas J. Steele

The problem with using single quotes with names is that some names have
apostrophes in them. You'll get an error using single quotes if the name has
an apostrophe.

One way around that issue is to double all apostrophes in the text:

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

Exagerated for clarity, that's


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

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Jim Burke in Novi said:
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 &
"'")


cmarsh said:
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

********************************
 
J

Jim Burke in Novi

Good point - I forgot about that issue.

Douglas J. Steele said:
The problem with using single quotes with names is that some names have
apostrophes in them. You'll get an error using single quotes if the name has
an apostrophe.

One way around that issue is to double all apostrophes in the text:

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

Exagerated for clarity, that's


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

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Jim Burke in Novi said:
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 &
"'")


cmarsh said:
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

********************************
 

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


Top