Newbie: By-passing confirmation dialog boxes

M

Mike

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

Douglas J. Steele

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

Roger Carlson

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
 
Top