detect docmd error even if setwarnings is OFF
Posted on 2011-09-07
Often, my vba programs need to analyze the cause of an error and take appropriate action.
But this is not easy when the error comes from a docmd method, when setwarnngs is off.
I want the my vba to see the EXACT same text that a user would have seen if setwarnings had been ON, but I do not want the user to see that text.
For instance the following code does not work
on error resume next
myerror$ = error$ ' THIS will always be blank. It fails because Access thinks that setwarnings false means "don't throw any errors".
on error goto myerr_routine
if myerror$ like "*unable to append*" then ....
In the past I have used many "tricks" to get around this problem but I am looking for a general solution that will work for all the many dozens of methods that could be invoked.