DEBUGGING ONE STEP AT A TIME

To work through some debugging situations, you need to be able walk a program line by line while it's executing. VBA provides four Step commands to accomplish this: Step Into, Step Over, Step Out, and Run to Cursor. You can use these commands after a program halts execution by choosing the appropriate command from the Debug menu.

Note

All four step commands skip over the same type lines of code that don't allow breakpoints: comments, declaring variables (the Dim statement), blank lines, and line labels or line numbers.


Stepping into Code Line by Line

The Step Into command steps through code lines one by one. When a code line has a call to another procedure, the editor then follows the code into it. This includes user-created functions and subroutines, but not intrinsic VBA functions such as Date() and Mid(). Calls into DLLs and OLE servers are also omitted.

First, halt program execution by pressing Ctrl+Break when the routine is executing, by setting a breakpoint, or by using a Stop statement. Then you can step through the code line by line, with the program pausing on each line, by either choosing the Step Into button of the Visual Basic toolbar, opening the Debug menu and then choosing Step Into, or pressing F8.

Stepping Through Code with Step Over

Similar to the Step Into command, the Step Over command takes you line by line through program execution. The difference comes when you're on a function or subroutine being called from within the original routine. When you use Step Over, rather than drop into the new routine, the program will

1.
Execute the new routine without displaying the code.

2.
Begin displaying the code line by line following the procedure call.

To use the Step Over command, simply press Shift+F8.

Tip

The Step Over command is useful when you have a number of routines that have been debugged thoroughly and can therefore be skipped.


Bailing Out of a Routine with Step Out

Sometimes when the going gets too tough, it's best just to bail out of the current routine and resume with the calling routine, in the line of code that follows the call.

The Step Out command allows you to leave a routine that might be messed up. You also can use Step Out if you don't need to bother with a particular routine, but accidentally went into it with the Step Into command.

You can use the Step Out command by pressing Ctrl+Shift+F8.

Skipping Tested Code with Run to Cursor

Think of when you're debugging the beginning of a routine. After the section of the code is tested, you find that you need to jump to the end of the routine. The method for doing this is Run to Cursor.

To perform a Run to Cursor from within the halted program, place the cursor where you want Access to execute the code to without stopping. Then press Ctrl+F8. The execution highlight will now be on the line of code in which you placed the cursor.

When you want the program to continue with regular execution, press F5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.244.201