Newbie: By-passing confirmation dialog boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey everyone,

I have a really simple button on a form that runs the following code:
DoCmd.RunSQL "DELETE tblACTT_Basic.* FROM tblACTT_Basic;"
DoCmd.RunSQL "DELETE tblACTT_Enhanced.* FROM tblACTT_Enhanced;"

Now, when I do this, it gives me the "Hey, y'know you're about to delete
"xxxx" records, you sure??" I'd like the application to "click yes" so the
end user does not get prompted with this. Is this possible?
 
Two ways:

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblACTT_Basic.* FROM tblACTT_Basic;"
DoCmd.RunSQL "DELETE tblACTT_Enhanced.* FROM tblACTT_Enhanced;"
DoCmd.SetWarning True

or (my preferred way)

CurrentDb.Execute "DELETE tblACTT_Basic.* FROM tblACTT_Basic;",
dbFailOnError
CurrentDb.Execute "DELETE tblACTT_Enhanced.* FROM tblACTT_Enhanced;",
dbFailOnError

The advantage of using the Execute method is that it will raise a trappable
error if anything goes wrong.
 
Two Solutions:
1) Use the Set Warnings to turn off the confirmation dialogs:
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblACTT_Basic.* FROM tblACTT_Basic;"
DoCmd.RunSQL "DELETE tblACTT_Enhanced.* FROM tblACTT_Enhanced;"
DoCmd.SetWarnings True

2) Use the Execute Method of the database object to run your queries:
Currentdb.Execute "DELETE tblACTT_Basic.* FROM tblACTT_Basic",
dbFailOnError
Currentdb.Execute "DELETE tblACTT_Enhanced.* FROM tblACTT_Enhanced",
dbFailOnError


--
--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
 

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

Back
Top