472,353 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Run-time Error 2001 you canceled the previous operation

I have been trying to figure this out for a couple weeks and after reading every post in the forum about the subject I have not found anything that works.
I have two tables;
1) has company numbers/cost centers, hierarchys, markets, and regions
2) the main table to which the information goes to.

I know it has something to do with the cost centers beacuse when I debug, everything else works.

My code is as follows;
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Co_Cost_Center_AfterUpdate()
  2.       Me.Hierarchy = DLookup("Hierarchy", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
  3.       Me.Market = DLookup("Market", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
  4.       Me.Region = DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'")
  5. End Sub 
When I go to tab out of the Co/cost ctr field it gives me the runtime error 2001 you canceled the previous operation.

Any ideas?
Apr 10 '07 #1
20 19968
pks00
280 Expert 100+
I take it the co_cost_ctr is alphanumeric and not just numeric

Another thing, DLOOKUP returns null if no records found. What are the types for the 3 fields you are setting? U could wrap DLOOKUP with NZ and supply a default value
eg

Me.Region = NZ(DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'"),"")


One more thing to try, your DB is not corrupt right. Ive heard before a corrupt db causing that error. Rare but has happened, so u could try a compact/repair or a decompile (always backup db first, stick with original if it makes no difference)
Apr 10 '07 #2
I take it the co_cost_ctr is alphanumeric and not just numeric

Another thing, DLOOKUP returns null if no records found. What are the types for the 3 fields you are setting? U could wrap DLOOKUP with NZ and supply a default value
eg

Me.Region = NZ(DLookup("Region", "[CostCtr/Hierarchy]", "[Co_Cost_Ctr] = '" & Me.[Co_Cost_Center] & "'"),"")


One more thing to try, your DB is not corrupt right. Ive heard before a corrupt db causing that error. Rare but has happened, so u could try a compact/repair or a decompile (always backup db first, stick with original if it makes no difference)
The co/cost center is alphanumeric. Im not sure I understand what you ean by the types for the three fields I am setting. They are all text fields if that is what you mean.

I tried compacting/repairing the database and it did nothing.

I will try the NZ thing but Im not sure what that will do.

I know it has something to do with the Co/cost ctr because that is where it gets stuck. Im fairly new with Access so I appologize for not understanding some of the things you are saying.
Apr 10 '07 #3
pks00
280 Expert 100+
No problems

Now when u perform a DLOOKUP, it is one fetch, if you are doing multiple DLOOKUPS using the same criteria, its slow (though u may not notice) so its better to use a recordset
eg

Expand|Select|Wrap|Line Numbers
  1. Private Sub Co_Cost_Center_AfterUpdate()
  2.     Dim rs as DAO.Recordset
  3.  
  4.     'Check if cost center specified
  5.     if IsNull(Me.Co_Cost_Center) = True then
  6.          msgbox "No Cost Center Found"
  7.     else
  8.         set rs=currentdb.openrecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'"
  9.  
  10.         'Check if cost center exists in db
  11.         if rs.eof = true then
  12.             msgbox "No records found for cost center " & Me.Co_Cost_Center
  13.         else
  14.             Me.Hierarchy = rs!Hierarchy
  15.             Me.Market = rs!Market
  16.             Me.Region = rs!Region
  17.         end if
  18.  
  19.         rs.close
  20.         set rs=nothing
  21. End Sub
  22.  

Does the above code make any sense to you?
Apr 10 '07 #4
pks00
280 Expert 100+
If it complains about

DAO.Recordset

ensure u have added Microsoft DAO Object Library v3.6
u do this by going into Tools/References (from vba window)
Apr 10 '07 #5
If it complains about

DAO.Recordset

ensure u have added Microsoft DAO Object Library v3.6
u do this by going into Tools/References (from vba window)
I put that code in but it gave me a syntax error on this line
Expand|Select|Wrap|Line Numbers
  1.         set rs=currentdb.openrecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'"
Am I supposed to change something?
Apr 10 '07 #6
pks00
280 Expert 100+
Sorry, forgot closing round bracket
air code typing


Set rs = CurrentDb.OpenRecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'")
Apr 10 '07 #7
Sorry, forgot closing round bracket
air code typing


Set rs = CurrentDb.OpenRecordset("SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.Co_Cost_Center & "'")
Ok so I fixed that and now it gives me run-time error 3061 too few parameters. Expected 1.

What does that mean?
Apr 10 '07 #8
pks00
280 Expert 100+
Ok, here is updated code, can u run it and check the immediate window
Ive added a debug.print, check the SQL that comes up, does it look valid?
also do a debug/compile as well




Private Sub Co_Cost_Center_AfterUpdate()

Dim rs As DAO.Recordset
Dim sSql As String


'Check if cost center specified
If IsNull(Me.co_cost_center) = True Then
MsgBox "No Cost Center Found"
Else
Debug.Print sSql
Set rs = CurrentDb.OpenRecordset(sSql)

'Check if cost center exists in db
If rs.EOF = True Then
MsgBox "No records found for cost center " & Me.co_cost_center
Else
Me.Hierarchy = rs!Hierarchy
Me.Market = rs!Market
Me.Region = rs!Region
End If

rs.Close
Set rs = Nothing
End If
End Sub
Apr 10 '07 #9
Ok, here is updated code, can u run it and check the immediate window
Ive added a debug.print, check the SQL that comes up, does it look valid?
also do a debug/compile as well




Private Sub Co_Cost_Center_AfterUpdate()

Dim rs As DAO.Recordset
Dim sSql As String


'Check if cost center specified
If IsNull(Me.co_cost_center) = True Then
MsgBox "No Cost Center Found"
Else
Debug.Print sSql
Set rs = CurrentDb.OpenRecordset(sSql)

'Check if cost center exists in db
If rs.EOF = True Then
MsgBox "No records found for cost center " & Me.co_cost_center
Else
Me.Hierarchy = rs!Hierarchy
Me.Market = rs!Market
Me.Region = rs!Region
End If

rs.Close
Set rs = Nothing
End If
End Sub

Now it says
Run-time error 3078
The Microsoft Jet database engine cannot find the input table or query". Make sure it exists and that its name is spelled correctly.

It points to this line
Set rs = CurrentDb.OpenRecordset(sSql)
Apr 10 '07 #10
pks00
280 Expert 100+
oh bugger, my bad. I forgot to set sSql

before debug.print sSql, add this line

sSql = "SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.co_cost_center & "'"
Apr 10 '07 #11
oh bugger, my bad. I forgot to set sSql

before debug.print sSql, add this line

sSql = "SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '" & Me.co_cost_center & "'"
The too few paramaters error comes up again.
In the code it highlights
Set rs = CurrentDb.OpenRecordset(sSql)
and in the immediate window it shows
SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
Apr 10 '07 #12
pks00
280 Expert 100+
when u run this sql in the sql window, does it work?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
Apr 10 '07 #13
when u run this sql in the sql window, does it work?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'
No it says compile error expected:case
Apr 10 '07 #14
pks00
280 Expert 100+
lets get the sql working first

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'

is this the table u are reading CostCtr/Hierarchy
does it have a field called Co_Cost_Center

the error is probably due to the sql not working
Apr 10 '07 #15
lets get the sql working first

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Center = '172/0009668'

is this the table u are reading CostCtr/Hierarchy
does it have a field called Co_Cost_Center

the error is probably due to the sql not working
In that table it is actually Co_Cost_Ctr
Apr 10 '07 #16
pks00
280 Expert 100+
So the query should be?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'

if the above sql works, then change the code as well and try it
Apr 10 '07 #17
So the query should be?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'

if the above sql works, then change the code as well and try it
I already tried that and it gives me the same error.
Apr 10 '07 #18
pks00
280 Expert 100+
Did the SQL work?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
Apr 10 '07 #19
Did the SQL work?

SELECT * FROM [CostCtr/Hierarchy] WHERE Co_Cost_Ctr = '172/0009668'
No it gave me the same error as before.
Apr 10 '07 #20
pks00
280 Expert 100+
can u confirm the name of the table/query is correct?

why not create a new query using the query wizard
Apr 10 '07 #21

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

Similar topics

3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run...
4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to...
2
by: Jenna Olson | last post by:
Hi all- I've never seen this particular issue addressed, but was wondering if there's anything to support one way or another. Say I have a class:...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification)...
19
by: Bryan | last post by:
How can i run a bit of code straight from the IDE? Right now i make a temporary button and put the code behind that, then i run debug mode and...
9
by: Brett Wesoloski | last post by:
I am new to VS2005. I changed my program.cs file to be a different form I am working on. But when I go to run the application it still brings up...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
7
by: mxdevit | last post by:
Task: run application from ASP.NET for example, you have a button on ASP.NET page, when press this button - one application is invoked. the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.