9.2. Two Kinds of Errors: Unexpected and Expected

All errors that your Access application may encounter fall into one of two categories: unexpected errors and expected errors. In this section we'll describe these two categories and what your application should do when errors in each category occur.

9.2.1. Handling Unexpected Errors

Unexpected errors are errors that you have no way of predicting, and that under normal circumstances should not occur. When your application encounters an unexpected error (for example, divide by zero or a missing object), and no error handling is in effect, Access will display an error message like the one above, and then abruptly end the procedure.

The goal of error handling in this case is not to solve the problem the error is indicating; there's nothing you can do about it now. Your code has tripped on an error and fallen down.

The only thing you can do is let the user know what happened calmly and in plain language. Figure 9-2 is an example of what your error message might look like.

Figure 9.2. Figure 9-2

There are several differences between the error message Access shows and the "handled" error message you can show:

  • The title of the message box can be specified by you instead of displaying "Microsoft Visual Basic" or "Microsoft Access."

  • You can show an icon to have a stronger impact.

  • You can add an explanation and text. You can even mention ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.