Stepping Through VBA Procedures

Stepping through the code means running one statement at a time. This allows you to check every line in every procedure that is encountered. To start stepping through the procedure from the beginning, place the cursor anywhere inside the code of your procedure and choose Debug | Step Into, or press F8. The Debug menu contains several options that allow you to execute a procedure in the step mode (see Figure 9-14).

Figure 9-14: The Debug menu offers many commands for stepping through VBA procedures.

When you run a procedure one statement at a time, Visual Basic executes each statement until it encounters the End Sub keywords. If you don't want Visual Basic to step through every statement, you can press F5 at any time to run the rest of the procedure without stepping through it.

© Hands-On 9-4: Stepping Through a Procedure

1. Place the cursor anywhere inside the procedure you want to trace.

2. Press F8 or choose Debug | Step Into. Visual Basic executes the current statement, then automatically advances to the next statement and suspends execution. While in break mode, you can activate the Immediate window, the Watches window, or the Locals window to see the effect of a particular statement on the values of variables and expressions. And, if the procedure you are stepping through calls other procedures, you can activate the Call Stack dialog to see which procedures are currently active.

3. Press F8 again to execute the selected statement. After executing this statement, Visual Basic will select the next statement, and again the procedure execution will be halted.

4. Continue stepping the procedure by pressing F8, or press F5 to continue running the code without stopping. You can also choose Run | Reset to

Introduction to Access 2003 VBA Programming stop the procedure at the current statement without executing the remaining statements.

When you step over procedures (Shift+F8), Visual Basic executes each procedure as if it were a single statement. This option is particularly useful if a procedure contains calls to other procedures you don't want to step into because they have already been tested and debugged, or because you want to concentrate only on the new code that has not been debugged yet.

0 0

Post a comment