O'Reilly logo

Access™ 2007 VBA Programmer's Reference by Armen Stein, Geoffrey Griffith, Rob Cooper, Teresa Hennig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.2. Two Kinds of Errors: Unexpected and Expected

All errors that your Access application may encounter fall into one of two categories: unexpected and expected. The following sections explain these two categories and what your application should do when errors occur in each of them.

9.2.1. Handling Unexpected Errors

Unexpected errors are ones 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 displays an error message like the one shown earlier and abruptly ends 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 that 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:

  • You can specify the title of the message box instead of displaying "Microsoft Visual Basic" or "Microsoft Access."

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

  • You can add a text explanation. You can even mention your phone number or other contact ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required