Can DoCmd.RunSQL be Done Quietly?

C

croy

When running an action query using the DoCmd.RunSQL
function, can the resulting message(s), such as "You are
about to delete...." be avoided?
 
R

Roger Carlson

You can either bracket it with the SetWarnings command:

DoCmd.SetWarnings False
DoCmd.RunSQL
DoCmd.SetWarnings True

or use the Execute method of the database object:

CurrentDb.Execute "yourquery"

The second method has the advantage of being faster and you can trap errors.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
C

croy

You can either bracket it with the SetWarnings command:

DoCmd.SetWarnings False
DoCmd.RunSQL
DoCmd.SetWarnings True

or use the Execute method of the database object:

CurrentDb.Execute "yourquery"

The second method has the advantage of being faster and you can trap errors.


Thanks, Roger. The SetWarnings way seems to work
beautifully. I haven't tried the Execute method, but I've
sure saved the info for future reference. Very helpful!
 
T

Tony Toews [MVP]

Roger Carlson said:
You can either bracket it with the SetWarnings command:

DoCmd.SetWarnings False
DoCmd.RunSQL
DoCmd.SetWarnings True

But also make sure you put the DoCmd.SetWarnings True line in the
error handling or wield things will start happening in your app. Or
rather expected warnings won't pop up especially when developing.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 

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