BaldyWeb

Stopping the Warnings When Running Actions Queries

How do I turn off warnings when using RunSQL?

Use

DoCmd.SetWarnings False

If you turn off warnings and forget to turn them back on (or if your code to turn them back on is never executed because of an error), you will get strange behavior, so make sure to turn them back on with:

DoCmd.SetWarnings True

It is best to include that in an error trap so it gets executed even if an error is raised.

However, you should not be using DoCmd.RunSQL. Use CurrentDb.Execute instead. It is much more efficient, does not raise the warning message boxes, and you can control if it fails on errors or not (sometimes you don't care if it fails).  There are certain instances where you can't use it, but when you can you should.  Depending on your situation, you can include the argument dbFailOnError.  More info on the Execute method in VBA help.

JasonM

Home