When would you use MacroError
in Access VBA code?
I have always used the Err
object for error handling. I recently came across some VBA code that had uses the MacroError
object instead. I read the MS doc on this object and it has a note:
The MacroError object does not contain information about run-time errors that occur when running Visual Basic for Applications (VBA) code.
Which is odd because the usage of MacroError
I was looking at was in a VBA procedure and it was used right after a DoCmd
call to check If MacroError.Number <> 0
. Shouldn't we use Err
for this?
REFERENCE: https://learn.microsoft.com/en-us/office/vba/api/access.macroerror
Access Macros have the ability to flow in to VBA and back again.
The MacroError
object allows you to check for errors in the macro part from VBA.
If you are only using VBA you would never need this. For VBA only you would stick with the regular Err
object for your error handling.
If you had an error in a macro, and then an error in VBA, you could end up with two different errors being held in each object.