DELETE Query

  • Thread starter Thread starter Erwin Bormans
  • Start date Start date
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
 
"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
 
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".
 
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.
 
Back
Top