vba code to suppress error messages

david.paton

Registered User.
Local time
Today, 01:58
Joined
Jun 26, 2013
Messages
338
Hi,

Could someone please show me what the vba code is to suppress error messages for an event. I know you can turn it off but I want it to turn off automatically for an event then I could put turn it back on after the event.

I looked online and I found this response but it didn't seem to work. This was the code:
DoCmd.SetWarnings false

What code could I put at either end of the event to suppress, reacctivate the error messages?

Thanks,
Dave
 
You use DoCmd.SetWarnings False before the silent code and DoCmd.SetWarnings True after it.

You can put these as the first and last executable statements of the event code to prevent anything in the event code from popping off a message. However, you should realize that suppressing errors is actually not always a good idea. It might be better to test for conditions before attempting something that would be doomed to failure (and error message issuances).

I also have a suspicion that there is more to this question than meets the eye. Events don't signal errors (usually). TRAPS signal errors that result in warning messages. My question is therefore to ask why you think that the SetWarnings (to False) didn't work when you tried it? In event code, if the code is generated by a wizard, it might not be possible to stop warnings using the .SetWarning action or method because the wizard often builds a trap handler that will use an explicit message-box function. I honestly don't recall whether .SetWarnings would block an explicit MsgBox call, but I don't think it does. So we will need a bit more information about the event.
 
I agree with Doc. Always better to test data input before trying to process it. Also error trapping, with or without a message to the user, can be used to record the problem in a log.

Also setwarnings will not suppress all warnings

Try
docmd.setwarnings false
debug.print 9/0

This will still give a run time error
 

Users who are viewing this thread

Back
Top Bottom