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

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 information.

□ You can format the error message with blank lines, commas, and so on.

□ Your user can't enter debug mode and look at your code.

0 0

Post a comment