VBA Error Handling

When programmers use the term error handling, they really mean graceful or planned error handling. After all, Access will take some kind of action for any error that it encounters in your code. Graceful error handling includes the following:

□ Quietly absorbing expected errors, so the user never sees them.

□ For unexpected errors, displaying a "friendly" message to the user, and closing the procedure properly.

Error handling in Access VBA involves adding code to every procedure (both subs and functions) to take specific action when Access encounters an error. This is called handling or trapping the error.

Some developers call the encounter with an error throwing an error. Error handling is the code that catches the error and handles it properly, either by hiding it from the user or by explaining it to them.

In this chapter, we'll cover techniques to handle several types of expected and unexpected errors, so that your applications look and feel more professional to your users. But first, we'll address why you should use error handling at all. Since many Access developers see it as a mundane chore, we want to present good reasons for including error handling in every procedure you write.

0 0

Post a comment