Dlookup run time error 2001

G

Guest

I continually get the message "you have cancelled the previous operation" run
time error 2001 when I use the following dlookup function

dim blp as string
blp = dlookup("[specialty]","operators","[init] ="&forms![anyform]![field]"

I have evencreated a new unbound form with no other code and still receive
this message.

Any help appreciated
 
A

Allen Browne

The error indicates that one of the 3 arguments for DLookup() is not
correct.

If init is a Number type field (not a Text type field), try:
Dim strWhere As String
Dim blp as Variant
strWhere = "[init] =" & forms![anyform]![field]
blp = DLookup("[specialty]", "operators", strWhere)

If it is a Text type field, you need extra quotes:
strWhere = "[init] =""" & forms![anyform]![field] & """"
 
G

Guest

Thank you, field is text, and the qoutation marks worked

Allen Browne said:
The error indicates that one of the 3 arguments for DLookup() is not
correct.

If init is a Number type field (not a Text type field), try:
Dim strWhere As String
Dim blp as Variant
strWhere = "[init] =" & forms![anyform]![field]
blp = DLookup("[specialty]", "operators", strWhere)

If it is a Text type field, you need extra quotes:
strWhere = "[init] =""" & forms![anyform]![field] & """"

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

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

Mike said:
I continually get the message "you have cancelled the previous operation"
run
time error 2001 when I use the following dlookup function

dim blp as string
blp = dlookup("[specialty]","operators","[init]
="&forms![anyform]![field]"

I have evencreated a new unbound form with no other code and still receive
this message.

Any help appreciated
 

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 2001 and DLookup 6
dlookup using variable as criteria 1
Run-time error '2001' 2
Error msg 2
Dlookup Frustration 2
DLookup 7
Error Msg 3
dlookup error 2001 1

Top