By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

in DLookup I get Error 2001 - says I cancelled previous operation. Huh?

P: n/a
I got this: "Error 2001 You cancelled the previous operation"

with this:

Private Sub courseCode_GotFocus()
Dim myDLookupResults As String
myDLookupResults = DLookup("courseID", "courses", "criteria= '" &
Forms!frmSelectCourses!courseDescription & "'")
lblMessages.Caption = "You are working on " & myDLookupResults
'insert myDLookupResults into a label called lblMessages
End Sub

The debugger correctly reads the record, so I don't think I have the wrong
code, or maybe I do. Any ideas?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The only possible problem I see with what you posted is your use of "Criteria"
as a field name. It may be a reserved word. Try changing it to something else
and see what happens.

<<'insert myDLookupResults into a label called lblMessages>>
What is this? Is there more code you did not post?

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:VC*****************@nwrddc02.gnilink.net...
I got this: "Error 2001 You cancelled the previous operation"

with this:

Private Sub courseCode_GotFocus()
Dim myDLookupResults As String
myDLookupResults = DLookup("courseID", "courses", "criteria= '" &
Forms!frmSelectCourses!courseDescription & "'")
lblMessages.Caption = "You are working on " & myDLookupResults
'insert myDLookupResults into a label called lblMessages
End Sub

The debugger correctly reads the record, so I don't think I have the wrong
code, or maybe I do. Any ideas?

Nov 13 '05 #2

P: n/a
The error message means that Access was unable to assign the value from
DLookup(), because one of the arguments was wrong (i.e. the previous
operation - retrieving the value - was not successful).

Examples of what to look for:
1. Is there a field named "courseID" without a space?
2. Is there a table or query named "courses"?
3. Does the table have a field named "criteria?"
4. What is the data type of the criteria field? If Number, drop the extra
quotes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:VC*****************@nwrddc02.gnilink.net...
I got this: "Error 2001 You cancelled the previous operation"

with this:

Private Sub courseCode_GotFocus()
Dim myDLookupResults As String
myDLookupResults = DLookup("courseID", "courses", "criteria= '" &
Forms!frmSelectCourses!courseDescription & "'")
lblMessages.Caption = "You are working on " & myDLookupResults
'insert myDLookupResults into a label called lblMessages
End Sub

The debugger correctly reads the record, so I don't think I have the wrong
code, or maybe I do. Any ideas?

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.