Access™ 2007 VBA Programmer's Reference
by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
Chapter 9. VBA Error Handling
When programmers use the term "error handling," they really mean graceful or planned error handling. After all, Access takes 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.
Displaying a "friendly" message to the user for unexpected errors, and closing the procedure properly.
Error handling in Access VBA involves adding code to every procedure—both subroutines (also known as subs) and functions—to take specific actions 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 users or by explaining it to them.)
This chapter provides techniques to handle several types of expected and unexpected errors so that your applications look and feel more professional to your users. But first, you'll explore why you should use error handling at all. Many Access developers see it as a mundane chore, but there are good reasons for including error handling in every procedure you write.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access