GZ said:
Hi,
When the sql contains "insert" or "delete", a message always popup.
How can I get ride of this kind popups?
Thanks!
GZ
If you use RunSQL, you have to turn warnings off before executing the
statement, and then BE SURE to turn them back on again after executing
it. Here's an example of the minimum safe arrangement:
'---- start of example code ----
On Error GoTo Err_Handler
DoCmd.SetWarnings False
DoCmd.RunSQL "your SQL statement"
After_RunSQL:
DoCmd.SetWarnings True
' ... other code, maybe ...
Exit Sub 'or Exit Function
Err_Handler:
MsgBox Err.Description
Resume After_RunSQL
End Sub 'or End Function
'---- end of example code ----
There are other ways of laying this out, but the main point is that
there's no way to get out of the procedure without executing
DoCmd.SetWarnings True.
If you're not wedded to the idea of using RunSQL, I recommend using the
DAO Execute method instead. That method doesn't require turning
warnings off. In its simplest form, it looks like this:
CurrentDb.Execute "your SQL statement", dbFailOnError
No warnings will be issued, but the dbFailOnError option will cause an
error to be raised in your code if there's an error executing the
statement. Note that failure to insert, update, or delete any records
does not constitute an error.