tags:

views:

177

answers:

3

in ms-access i am running a macro that runs several queries, during the execution of a query a message box appears

"you are about to run an update.......... are you sure you want to run this query ? "

how can i automatically select for all such cases so that macro runs without human intervention.

+1  A: 

You can turn off temporary the warnings like this:

DoCmd.SetWarnings = False
DoCmd.RunSQL ...
DoCmd.SetWarnings = True
Nick D
This is bad advice as 1) you also need to add docmd.setwarnings = true to error handling; 2) running execute will give you much better errors.
Tony Toews
+1  A: 

It is generally best to use Execute in such cases in order to trap errors:

Dim db As Database, qdf As QueryDef, strSQL As String

Set db = CurrentDb
Set qdf = db.QueryDefs("Query17")
qdf.Execute dbFailOnError
Debug.Print qdf.RecordsAffected

Or

strSQL="UPDATE SomeTable SET SomeField=10"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected

Trapping errors with dbFailOnError and an error trap is more or less essential and there are a number of other useful aspects to the Execute Statement

Remou
Unless you need the recordsaffected value you don't need to define the db or qdf.
Tony Toews
+1  A: 

To avoid having to write the code @Remou supplies every time you execute arbitrary SQL you could use my SQLRun function, which is designed as a dropin replacement for DoCmd.RunSQL and avoids all the problems therewith.

David-W-Fenton
Which code did Tony supply, please?
Remou
@Remou: you're right -- it appears it was your code that I was referring to. Post corrected.
David-W-Fenton