Running Selected Portions of Code
If you know exactly which statement caused an error, using a single breakpoint may be sufficient. More often, however, you can only guess the general vicinity of the statement that caused the error. Setting a breakpoint helps you get to that general area. Once there, you can step through your code and run it line by line to see the effect of each statement.
You can also step through each line of code in a called procedurea procedure the current procedure calls
or step over the called-procedure code. (Stepping through statements is sometimes referred to as tracing.) If necessary, you can also back up and start execution at a previous line.
Stepping Through Statements
Stepping is the process of running one statement at a time. After running each statement, you can see how it affected the variables and objects in the database.
  To step through code one statement at a time
Click the Step Into button on the toolbar.
When the Step Into command is carried out, Visual Basic runs the current statement and then automatically advances to the next statement and suspends execution.
A line of code can contain two or more statements separated by a colon (:). You can step from one statement to the next even if they are on the same line. However, breakpoints apply only to the first statement in a line.
Note   If your Microsoft Access workgroup has security enabled (if you logged on by using the Logon dialog box), you can step through code in a called procedure only if you have Read Design permission for the called procedure's module. If you try to step into a called procedure and you don't have Read Design permission for the called procedure's module, Visual Basic runs the called procedure without stepping through the code one statement at a time.
Tip   You can also step through code by placing the cursor within the procedure and pressing F8. If at any point you want to run the rest of the procedure without stepping through it, press F5.
Stepping Over Procedures
If you don't want to step through the lines of code in a called procedure, you can step over the entire procedure.
  To step over an entire procedure
Click the Step Over button on the toolbar.
The Step Over command is identical to the Step Into command except when the current statement contains a call to a procedure. The Step Into command steps into the procedure that was called and lets you step through it line by line, but the Step Over command runs the called procedure as a unit and then steps into the next statement in the current procedure. For example, suppose the current statement calls the procedure GetQueryCriteria:
GetQueryCriteria strCriteria
If you use the Step Into command, the Module window displays the GetQueryCriteria procedure and the first statement in that procedure is the current statement. The Step Into command is the best choice if you want to analyze the code within GetQueryCriteria.
If you use the Step Over command, the Module window continues to display the current procedure while Visual Basic runs the GetQueryCriteria procedure. Execution then advances to the statement immediately after the call to GetQueryCriteria. Step Over is a better choice than Step Into if you want to stay within the current procedure and don't need to analyze how GetQueryCriteria works.
Stepping Out of Procedures
If you step into a procedure and then decide that you don't want to step all the way through it, you can step out of the procedure.
  To step out of a procedure
Click the Step Out button on the toolbar.
When the Step Out command is carried out, Visual Basic runs the rest of the procedure, including any nested procedures that it calls, in one step. Execution stops when it returns to the calling procedure. If the current procedure wasn't called by another procedure, the Step Out command has the same effect as the Continue command; that is, the current procedure runs to completion.
You can freely alternate between the Step Into, Step Over, and Step Out commands. The command you choose depends on which portions of code you want to analyze at any given time.
Setting the Next Statement to Be Run
When you know a certain section of code is causing trouble, you may want to skip over it. This doesn't solve the problem, of courseeventually, you'll have to debug that section. However, skipping lines of code enables you to move on and examine other parts of your code.
At other times, you may want to rerun previous lines of code in the procedure. Perhaps you've modified those lines or changed the value of a variable and want to see if these changes produce different results.
Visual Basic enables you to continue execution at a line of code other than the next one as long as that line is within the same procedure.
  To set the next statement to be run
Right-click the line of code where you want to continue execution, and then click Set Next Statement on the shortcut menu.
You can choose to continue execution or step through the lines of code starting with the statement you set.
Important   You can use the Set Next Statement command in a procedure only if you've suspended execution in that procedure.
You can also use the Run To Cursor command (Debug menu) to run your application until the line that you have selected is run. You may find this command useful if you want to stop execution before a large loop farther down in your code. Or you may want to use this command if you're sure that a certain section of your code is functioning properly, and you want to continue troubleshooting later in the procedure. To run code until it comes to a specific line, right-click the line of code, and then click Run To Cursor on the shortcut menu.
© 1996 Microsoft Corporation. All rights reserved.