Error Handling using Module

Malcolm17

Member
Local time
Today, 13:21
Joined
Jun 11, 2018
Messages
107
Hello,

I'm looking to re-do my Error Handling as it seems to be quite messy, at the moment I use the same code in each VBA entry; On Load, Click etc. I have a large system with lots of forms etc so I was looking to call a module that would hold the error handling in it for all area's. I use the error handling to stop any breaks and also to display a message box and log the error in a table.

Can anyone point me in the right direction for this please or ideally maybe share an example with me?

Thank you,

Malcolm
 
I would search this site and Google. I thought for sure I would find a centralized error handler, but could not. FMSINC.COM has one but not free.
Error Handling - VBA Module: Global error handler for Microsoft Access VBA. Added to every procedure, these routines will trap, document, email, and gracefully exit your application when unexpected errors occur (fmsinc.com)
I found this in a thread with some code.
VBA Excel Error Handling - especially in functions - Professional Excel Development Style - Stack Overflow

If writing a lot of code MZTOOLS is a great investment. I think around $70. It has a feature to insert error handling.
A lot of these centralized modules will log the errors to a file, table, or even send email alerts.

I personally have gone away from a centralized error handler, I just find it is as much work. (Especially since i use MZTOOLS)
 
If you really want to use a "combined" error handler (perhaps to unify the format of the error presentation or to do logging), don't forget this very important fact: In the local code context of a form, the Me.xxx construct works. However, if you make a common module in a general module, you leave the form's code context and while you are in that code, Me.xxx has no meaning. Therefore you need to remember to pass in to the subroutine anything you wanted to show in the logging history or the error message notification function. That includes the name and properties of the form. If none of the references that my colleagues have provided help you, come back with specifics of what you need to know.
 
Error handling is about catching specific errors and handling them. I find that the messages I display and what I do for the same error message can be different when the error is found in a different context. So be careful how you standardize this. However, if you want to log errors and/or send emails to yourself or others, that lends itself well to being standardized. If you find yourself needing case statements or nested Ifs in the common routine, you have not standardized the process, you have complicated it by coupling a bunch of procedures that should stand alone.
 

Users who are viewing this thread

Back
Top Bottom