DELETE Query

E

Erwin Bormans

Hi all

When I run the following code:

sql = "DELETE Scheuten.* FROM Scheuten"
DoCmd.RunSQL sql

He always asks the user if he wants to continue with this delete query. Is
there a way to avoid this question and just run this sql statement?

Kind regards
Erwin
 
D

Dirk Goldgar

"Erwin Bormans" wrote in message
Hi all

When I run the following code:

sql = "DELETE Scheuten.* FROM Scheuten"
DoCmd.RunSQL sql

He always asks the user if he wants to continue with this delete query. Is
there a way to avoid this question and just run this sql statement?


In an MDB or ACCDB file, you can write:

CurrentDb.Execute sql, dbFailOnError
 
C

cw

To my knowledge you can NOT turn off this function for just one query. As
far as I know it is a all or nothing. Meaning you can turn off all warning
in your database which I would NEVER recommend.

However, there is a work around.

You can create a Macro to run the query.
When they click on the macro the query will run without warnings.

In the Macro design you would choose "SetWarnings" - In the Action drop down
- then in the lower part of the screen you need to set the Warning On to "NO".
 
K

Ken Snell \(MVP\)

sql = "DELETE Scheuten.* FROM Scheuten"
DoCmd.SetWarnings False
DoCmd.RunSQL sql
DoCmd.SetWarnings True


Be careful with the above code, though. If you have an error handler routine
in your procedure, be sure to put this line in that error handler code too
(so that you turn the warnings back on in case the line is missed in your
above code because an error causes the VBA processor to jump to the error
handler):
DoCmd.SetWarnings True

Turning off the warnings in code will turn them off all through the
database, and you won't be able to turn them back on in the Tools | Options
settings; you can only turn them back on by running that "true" code line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top