Have you ever seen a code error highlighted in yellow when your code runs?
If so, and you don't want your users put in that situation, then you need to
include an error handler in almost every procedure you create.
Even a simple procedure that consists of:
DoCmd.OpenReport "Report1"
needs an error handler. For example, if the user gets impatient and presses
Ctrl+C to cancel the report (or if it is cancelled by its NoData event), you
will have to handle error 2501.
There are a (very) few things that don't need an error handler, such as a
procedure that consists of nothing but:
Beep
You could also make an exception if your routine calls a function that has
its own error hander. In general, though, you waste more time trying to
figure out if it could be be an exception than you would in just adding the
error handler. It never hurts to add it; you will get caught if you try to
skimp.
Theoretically, you can also leave out the error handler in a routine that is
only called by another routine that has error handling, since the calling
routine's error handler will trap errors generated by the child process. In
practice, this makes debugging harder IMHO, because the error may not have
been generated by the routine that reports it. Anything that helps debugging
is worthwhile, so again, use error handling in any process. (It also means
your code is more re-usable if it has its own error handler.)
If it seems like a pain to add the error handler lines to every procedure,
go to
www.mztools.com and download the routine that inserts it with just a
mouse click.
You might also consider logging the errors, so you have a history of what
happened. Again this can be useful for debugging, even remote debugging if
someone else is using your database. For suggestions on how to do that, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
That logging is what I personally do, using mztools to insert the routine in
every procedure. The mztools mouse click makes that so easy.