Error 2001: "You cancelled the previous operation" (1 Viewer)

R2D2

Registered User.
Local time
Today, 01:07
Joined
Jul 11, 2002
Messages
62
I have some code in a command button on a form that generates Error 2001: "You cancelled the previous operation."

I've searched this forum for fixes, and the only suggestion I found which might work for me is creating a new database and importing everything from the current one. I've tried this and it doesn't work - I get the same problem. So I don't think it's being caused by a corrupt database.

Here's my code:

Private Sub Command37_Click()
On Error GoTo Command37_Click_Error

DoCmd.SetWarnings False

DoCmd.OpenQuery "qryCheckImportedTotals"

If (DCount("*", "tblSSTotalsExceptions", "(([tblSSTotalsExceptions].[Year] = [tblImportedTest].[Year]) AND ([tblSSTotalsExceptions].[Payno] = [tblImportedTest].[Pay No]) AND ([tblSSTotalsExceptions].[Week] = [tblImportedTest].[Week No]))") > 0) Then

If (MsgBox("The totals listed on the Excel spreadsheets don't match the sum total of the individual records. Would you like to see tblSSTotalsExceptions?", vbYesNo + vbQuestion) = vbYes) Then
DoCmd.OpenTable "tblSSTotalsExceptions"
End If
End If

DoCmd.SetWarnings True

Command37_Click_Exit:
Exit Sub

Command37_Click_Error:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Command37_Click_Exit

End Sub

When I Debug, the problem registers on the "If (DCount ..." line.

Does anyone know what's causing this problem, and how I might fix it?

thanks!
 

R2D2

Registered User.
Local time
Today, 01:07
Joined
Jul 11, 2002
Messages
62
qryCheckImportedTotals is an append query that adds records to tblSSTotalsExceptions. Sometimes it finds records to add and sometimes it doesn't. My If statement is trying to find out if any of these records were found.

Your question actually gave me an idea for a solution: I split qryCheckImportedTotals into 2 queries, one that selects the records (qryCheckImportedTotals1) and one that appends it to the table (qryCheckImportedTotals2). Then I changed the OpenQuery and DCount lines to be:

DoCmd.OpenQuery "qryCheckImportedTotals2"

If (DCount("*", "qryCheckImportedTotals1") > 0) Then

I've tried this, and it fixes my problem. However, I'd still be curious to hear what was causing the error - the code I had before sure seems like it should work. Anyone got any information on the error?

Rich, thanks for the help!
 
R

Rich

Guest
I'm guessing that the append query hasn't finished before your trying DCount, I'm not even sure you can DCount on an append query
 

R2D2

Registered User.
Local time
Today, 01:07
Joined
Jul 11, 2002
Messages
62
You're right - you can't DCount on an append query. That's why I was using DCount on the table I was appending my records too. I replaced this with a DCount on a select query (which a second query, my append query was built off of).
 

Rakier

Registered User.
Local time
Today, 01:07
Joined
Mar 21, 2002
Messages
75
Whenever I get that error, it is usually because of a spelling mistake somewhere in the code, not with the command words and syntax but with the name of a table or query. Not sure if this is the case with you, but double-check all of the spelling first.
 

Philem

New member
Local time
Yesterday, 20:07
Joined
Mar 18, 2003
Messages
5
Downline problem

R2,

Recently had the exact same problem on Acc97. It was caused by one of the underlying queries not working properly. Check that EACH query referenced in the code, including all sub-queries, are working. This error comes when the queries cannot execute.

HTH!

P
 

Users who are viewing this thread

Top Bottom