Turn Alerts Off

  • Thread starter Thread starter T Liden
  • Start date Start date
T

T Liden

When I run the following code the user is prompted to make sure they want to
delete the records, but I want the records to be deleted automatically
without any prompts. Is there a way to turn the alerts off??

DoCmd.RunSQL ("Delete from Receiv1")

Thanks in advance for your help!!
Tim
 
Gary Miller said:
Tim,

DoCmd.SetWarnings False
DoCmd.RunSQL ("Delete from Receiv1")
DoCmd.SetWarnings True

It is also a good idea to put the SetWarnings True in your error
handling in case the code breaks while the Warnings are still turned
off as all warnings in Access will remain off.

A handy alternative for setting warnings on and off -- provided you're
working in an .mdb and not an .adp -- is to use the Execute method of
the DAO Database object returned by the CurrentDb() function:

CurrentDb.Execute "Delete from Receiv1", dbFailOnError

No warning will be displayed, though an error message will be displayed
if for some reason the query can't be executed.
 
Back
Top