Access™ 2007 VBA Programmer's Reference
by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
8.7. Debugging VBA
Programming in VBA isn't easy. No matter how skilled you are there are times when you need help figuring out what the code is actually doing. Fortunately, VBA provides a rich and powerful debugging environment. You can stop the code at various times and for various reasons, view values of variables (and even change them), and step through your code line-by-line until you understand what's going on.
The main reason you need to debug your code is because Access has displayed an error message. (Hopefully you've put error handling in your code, which can make this activity easier. This topic is covered extensively in Chapter 9.) Let's say you've coded a cool copy routine like the one shown earlier in this chapter. However, when you try it, Access displays an error. If you don't have error handling, a message box displays, as shown in Figure 8-2.
Figure 8.2. Figure 8-2
If you do have error handling, good job! Your error handling message box will display, as shown in Figure 8-3.
Figure 8.3. Figure 8-3
When Access displays your handled error message box, your code execution is suspended. To debug your code, press Ctrl+Break to interrupt code execution and display the dialog box shown in Figure 8-4.
Figure 8.4. Figure 8-4
Whichever way you get there, you can finally ...
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