Error Msg

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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"""
 
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
 
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.
 
Back
Top