Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Query Error Message - Need help Quickly!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a query and I'm able to run it once, but when I try and run it again i get the error: Run-Time error '2001': "You canceled the previous operation" What does this mean? I posted the code that its giving me the error on. It's a command button known as cmdSrch. The debug is pointing at the line that reads

--> docmd.openQuery "or query"

rem Code below...

If ((Opt1.Value = 0) And (Opt2.Value = 0)) Or Check83.Value = False Then
MsgBox "Please select an option AND enter at least one criteria"
End If

Rem Check to see which query to run

If Opt1.Value <> 0 Then
DoCmd.OpenQuery &quot;and query&quot;
Else
DoCmd.OpenQuery &quot;or query&quot;
End If


REM Reset Values

Check83.Value = False: Check76.Value = False: Check74.Value = False: Check72.Value = False
Check70.Value = False: Check68.Value = False: Check66.Value = False: Check64.Value = False

Text1.Value = &quot;&quot;: Text2.Value = &quot;&quot;: Text3.Value = &quot;&quot;: Text4.Value = &quot;&quot;:
Text5.Value = &quot;&quot;: Text6.Value = &quot;&quot;: Text7.Value = &quot;&quot;: Text8.Value = &quot;&quot;

Text1.Visible = False: Text2.Visible = False: Text3.Visible = False: Text4.Visible = False:
Text5.Visible = False: Text6.Visible = False: Text7.Visible = False: Text8.Visible = False

End Sub
 
try changing the names of the querys &quot;and&quot; &quot;or&quot; are reserved words......... try &quot;AndQuery&quot;, &quot;OrQuery&quot;, this may not fix this particular problem, but its something you should try to avoid in the future.

PaulF
 
hi,

If you run the query the second time, are you sure the query is closed. You can't open a query or table if it is already open
 

DoCmd.Close acQuery, &quot;OrQuery&quot; Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
I did what was suggested and I am still getting that same error. I do Not understand it at all!!!!.... Here is the piece of my code again, I put the close statements at the top. It just doesn't make sense why it keeps on giving me that &quot;You canceled the previous operation&quot; at the line Docmd.openquery &quot;QueryOr&quot; It's mind boggling :( I have been trying to figure this out for weeks now and I just want to get this fixed. If anyone can piece together why my database is doing this it would be a relief! Does anyone think it has anything to do with my IF statement? Thanks

*************************************************
Private Sub Command78_Click()
DoCmd.Close acquery, &quot;Queryor&quot;
DoCmd.Close acquery, &quot;QueryAnd&quot;
If ((Opt1.Value = 0) And (Opt2.Value = 0)) Or Check83.Value = False And Check76.Value = False And Check74.Value = False And Check72.Value = False And Check70.Value = False Then
MsgBox &quot;Please select an option AND enter at least one criteria&quot;
Exit Sub
ElseIf Opt1.Value <> 0 Then
DoCmd.OpenQuery &quot;QueryAnd&quot;
Else
DoCmd.OpenQuery &quot;QueryOr&quot;
End If

Check83.Value = False: Check76.Value = False: Check74.Value = False: Check72.Value = False
Check70.Value = False: Check68.Value = False: Check66.Value = False: Check64.Value = False

Text1.Value = &quot;&quot;: Text2.Value = &quot;&quot;: Text3.Value = &quot;&quot;: Text4.Value = &quot;&quot;:
Text5.Value = &quot;&quot;: Text6.Value = &quot;&quot;: Text7.Value = &quot;&quot;: Text8.Value = &quot;&quot;

Text1.Visible = False: Text2.Visible = False: Text3.Visible = False: Text4.Visible = False:
Text5.Visible = False: Text6.Visible = False: Text7.Visible = False: Text8.Visible = False
Opt1.Value = 0
Opt2.Value = 0
End Sub
*********************************
 

Perhaps there is an error in the query. Often, Access reports an error code when there is actually another cause. For example, do the queries have selection criteria where a numeric value is enclosed in quotes? This may cause the error you are experiencing.

Post the SQL view of the query so we can analyze it. Perhaps, we'll see something that will help. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top