Error 2001

nishanth

New member
Local time
Today, 22:50
Joined
Sep 21, 2008
Messages
1
Hi,
i am very new to access.
i created a database for my office. I created a delete query which is run fro the switchboard by a command button.when i cancel my query i get a error 2001.when i debug it takes me to the line DoCmd.OpenQuery "del Officer Details Query". Can any one hep me
 
[FONT=Verdana, Arial, Helvetica]Error 2001 is an error message you recieve when "[/FONT][FONT=Verdana, Arial, Helvetica]You canceled the previous operation"

My personal suggestion would be to instead of having the prompt coming up asking the user to confirm that they want to delete the records, in the VBA have the following code

[/FONT]
Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "del Officer Details Query"
DoCmd.SetWarnings true

This should cause the query to be run without asking the user to confirm.

If you want the user to confirm then you should do something like this

Code:
If MsgBox("Are you sure you would like to run the Delete query?", vbYesNo, "Confirmation") = vbYes Then
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "del Officer Details Query"
    DoCmd.SetWarnings True
End If

This will prompt the user asking whether they would like to run the delete query, then if they click yes it runs the query else it does nothing and just continues executing the rest of the sub (although Im sure you could have figured that out from the code :P)

On a seperate not I would suggest having a think about your naming of the query, while technically theres nothing wrong with it, its generally advised not to have spaces in the names for objects like reports, forms, queries and tables.
It is also common practice to prefix your objects with three characters to help identify what type of object it is.
For example
frm for Forms
tbl for Tables
qry for Queries
rpt for Reports.

Anyway I hope that the answer I provided above has helped, and I hope you will at least consider my suggestions about naming.

Satal :cool:
 
I think the OpenQuery action attempts to display rows returned by a query, however a delete query doesn't return rows. This may be the cause of your error.
You may want to look at using a construct like...
Code:
CurrentDb.Execute "YourQuery"
...which executes an action query without any warnings.
 
I quickly tested it and at least on my system if it was a delete query it didn't show you the rows if you ran it how I showed
 

Users who are viewing this thread

Back
Top Bottom