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

Run time error 2001

P: 60
Sorry to keep asking questions but I keep getting a run-time error 2001 "you canceled the previous operation" error whenever the code in the Dlookup line is reached. I have a table called Alphabet_lookup that I'm simply trying to extract a letter from depending on the value of counter . I first thought that "Letter" might be a reserved word so I changed the field name and still get the same error.

It's frustrating spending an entire afternoon on something like this. Thanks for any help.

Splits = Val([Forms]![Splits_Form]![Number_of_Splits_Textbox])
Dim ltr As String
Do While COUNTER <= Splits

ltr = DLookup("[LETTER]", "Alphabet_lookup", "[split_num] = Counter")
Set db = CurrentDb
Set rs = db.OpenRecordset("Count_Stations")
rs("PCID") = DMax("[PCID]", "Count_Stations") + 1
rs("Counting_S") = Forms!count_stations_form!COUNTING_S & ltr & "-" & get_global("g_group")
rs("Street") = Forms!count_stations_form!STREET
rs("Cross_St1") = Forms!count_stations_form!CROSS_ST1
rs("Cross_St2") = Forms!count_stations_form!CROSS_ST2
rs("Cnty_fips") = Forms!count_stations_form!CNTY_FIPS
rs("Status") = "add/split"
rs("Action_Note") = "ADD:as per SPLIT"
rs("Creation_date") = Date

If COUNTER = Splits Then
done = yes
Exit Do
End If
Loop Until done = yes
Nov 26 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,287
"[split_num] = Counter")

should be

"[split_num] = " & Counter)

Nov 26 '08 #2

P: 60
Thank you Chip! That fixed it right up. You are indeed a gentleman!
Nov 26 '08 #3

Expert 2.5K+
P: 3,532
The syntax Chip gave you is valid when the field in the Where condition is Numeric. Fields that are Text or Date require a slightly different syntax. For future reference:

'Where EmpNameID is Numeric
Expand|Select|Wrap|Line Numbers
  1.  Me.Wage = DLookup("wage", "Employees", "[NameID] = " & Me.EmpNameID)
'Where EmpNameID is
Expand|Select|Wrap|Line Numbers
  1. Text
Me.Wage = DLookup("Wage", "Employees", "[NameID] = '" & Me.EmpNameID & "'")

'For Date fields
Expand|Select|Wrap|Line Numbers
  1. DLookup("[FieldNameToReturn]", "TableName", "[CriteriaField] = #" & Me.YourDate & "#")
This same type of syntax is also valid when using DLookUp(), DMax() DSum() and so forth.

And to both of you, Welcome to Bytes!

Linq ;0)>
Nov 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.