Error Msg

G

Guest

Good day,
I have put the below into Module1 and get an error message "Run-Time error
'2001'"
"You canceled the previous operation". Can anybody tell me what is wrong ?

Sub test()
Dim varX As Variant
varX = DLookup("[LastName]", "tblQualityStaff", "[EmployeeID] = 1")
MsgBox varX
End Sub
 
A

Allen Browne

DLookup() returns that error if one of the arguments is malformed.

Is the table name tblQualityStaff?

Does that table contain fields named LastName and EmployeeID (no spaces)?

Is EmployeeID a Number type field? If it is Text, you need extra quotes in
the 3rd argument:
"[EmployeeID] = ""1"""
 
G

Guest

Thanks a million Allen, the help file and my books do not show the extra
quotes in the third argument.
Thanks again
--
Les


Allen Browne said:
DLookup() returns that error if one of the arguments is malformed.

Is the table name tblQualityStaff?

Does that table contain fields named LastName and EmployeeID (no spaces)?

Is EmployeeID a Number type field? If it is Text, you need extra quotes in
the 3rd argument:
"[EmployeeID] = ""1"""

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Newbie said:
Good day,
I have put the below into Module1 and get an error message "Run-Time error
'2001'"
"You canceled the previous operation". Can anybody tell me what is wrong ?

Sub test()
Dim varX As Variant
varX = DLookup("[LastName]", "tblQualityStaff", "[EmployeeID] = 1")
MsgBox varX
End Sub
 
F

fredg

Good day,
I have put the below into Module1 and get an error message "Run-Time error
'2001'"
"You canceled the previous operation". Can anybody tell me what is wrong ?

Sub test()
Dim varX As Variant
varX = DLookup("[LastName]", "tblQualityStaff", "[EmployeeID] = 1")
MsgBox varX
End Sub

Why are you declaring varX as Variant rather than as a String?

Assuming all the table and field names are correct, and there is an
EmployeeID = 1, your above DLookUp should work.

Perhaps you are getting your error elsewhere in whatever other code
you have going on.
 

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

Top