How to get ride of popup message from DoCmd.RunSQL?

G

GZ

Hi,
When the sql contains "insert" or "delete", a message always popup. How can
I get ride of this kind popups?
Thanks!
GZ
 
D

Dirk Goldgar

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.
 

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

Top