View Full Version : Delete Query
znet2705zc
Mar 21, 2010, 12:07 AM
Hi ,
In My project (Access 2007) , I Used a "Delete Query" To Delete A Record.
When The Query Is Runnig ,It Ask About Deleting A Record.
Can We Umit That Message?(In Other Hand , It Delete A Record Without Asking)
Thanks.
ScottGem
Mar 21, 2010, 02:24 AM
How are you triggering the query?
znet2705zc
Mar 21, 2010, 11:37 AM
What do you mean?
ScottGem
Mar 21, 2010, 11:51 AM
A Delete query is an Access object that removes records from a table. To run a Delete query, you have to trigger it in some way. You could simply double click the query name in the Navigation Pane or you can call the query from a macro or on a button on a form.
If you are just running it from the Nav Pane, then there is no way to turn off the Warnings. If, you run it from a macro or from a VBA module, there are ways to turn off the warnings. That's why I asked how you trigger it so I can know what the best way to tell you how to do it is.
It would also help to know what record you are deleting or to see the SQL for the query. You would have to be providing some criteria for the query so you don't delete all the records in the table.
znet2705zc
Mar 21, 2010, 12:27 PM
I click a button that it run a macro.
And criteria is : [Forms]![main_form]![Txt_del]
ScottGem
Mar 21, 2010, 02:39 PM
Ok, In the macro add a line before you execute the query:
SetWarnings False
After the query add a line:
SetWarnings True
znet2705zc
Mar 21, 2010, 11:22 PM
I Tried , But I couldn't.
The Macro is Like The Follow , Can you Explain More ?
Macro Name :
Condition :
Action : OpenQuery
Argument :Q_Del,DataSheet,ReadOnly
ScottGem
Mar 22, 2010, 03:59 AM
I generally do not use macros they are too limiting. But in a macro each action is a line. What you show above is is the OpenQuery line. You need to ADD lines above and below that line to turn SetWarnings on and off.
The VBA code would be:
SetWarnings False
DoCmd.OpenQuery "Q_Del"
SetWarnings True
You don't need the other parameters for the OpenQuery method as they are the defaults.
znet2705zc
Mar 22, 2010, 08:21 AM
I Added That Two Line , And The Result was This Error :
Compile Error: Sub Or Function Not Defined.
ScottGem
Mar 22, 2010, 09:25 AM
You added them to the macro? Did you pick SetWarnings from the list of Actions?
znet2705zc
Mar 23, 2010, 12:55 PM
No, I didn't.
Now I do that , and finally it solve.
Thanks a lot.
ScottGem
Mar 23, 2010, 01:36 PM
You're welcome