Responding to Errors

The main reason you'll 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 handing, a message box will be displayed, as shown in Figure 8-2.

If you do have error handling, good job! Your error handling message box will be displayed, as shown in Figure 8-3.

When Access displays your handled error message box, your code execution is suspended. To get the opportunity to debug your code, press Ctrl-Break on your keyboard to interrupt code execution and display the dialog box shown in Figure 8-4.

Figure 8-2
Figure 8-3
Figure 8-4

Whichever way you get there, you can finally click the Debug button. When you do, your code appears in the VBA code window. If you are not using error handling, the line of code that caused the error will be highlighted in yellow. If you are using error handling with an extra Resume statement as described in Chapter 9, you can reposition to the line that caused the error, as shown in Figure 8-5.

Figure 8-5
0 0

Post a comment