Use the SetWarnings macro action to turn off the confirmation
message prompts.
Well, I think that's a really bad idea.
I recently had a very old application of mine break when converted
from A97 to A2K3 because A2K3 resolves form control references
differently than A97. The control references were in the saved
QueryDefs and they pulled the right values in A97 but came out as a
zero-length string in A2K3.
Now, the problem was that I was running a bunch of these queries in
a row with SetWarnings turned off (yes, I was not too clever in my
Access programming 10 years ago). The problematic query would have
shown an error if SetWarnings had been ON (because the destination
fields in the append cannot contain ZLS's), but it wasn't. The
result was that my client lost several days of invoice payment
record detail (the payments were recorded, but the payment dates and
check numbers were lost, because of the control references that
weren't resolving the same).
So, I would basically say:
Never use DoCmd.RunSQL or DoCmd.OpenQuery or a macro to execute a
query, unless you can afford to have the confirmation messages come
up.
To fix the problem, I converted the problem queries to be
CurrentDB.Execute, and resolved the control references to actual
values before constructing the SQL string.
I know that for a macro coder that's probably beyond their
abilities, but, well, I don't know a better solution.
Here's a quick-and-dirty ExecuteSQL function that could be called
with RunCode from a macro:
Public Function ExecuteSQL(strSQL As String, _
Optional db As DAO.Database) As Long
On Error GoTo errHandler
Dim bolSetDB as Boolean
If (db Is Nothing) Then
Set db = CurrentDB()
bolSetDB = True
End If
db.Execute strSQL, dbFailOnError
ExecuteSQL = db.RecordsAffected
exitRoutine:
If bolSetDB Then
Set db = Nothing
End If
Exit Function
errHandler:
'MsgBox Err.Number & ": " & Err.Description, _
vbCritical, "Error in ExecuteSQL()"
Resume exitRoutine
End Function
This function returns the numbers of records that are
updated/deleted/appended.
One could alter it to return some kind of negative value if, for
instance, an error occured. This would be done in the errHandler
before the Resume command:
ExecuteSQL = -9999
You could choose any negative number other than -1 (though you could
use that if you liked, I wouldn't, since it's the value of True).
You would call this with Runcode and supply one argument, the SQL
string (which could be the name of a saved query).