Add a breakpoint to suspend execution of Microsoft Visual Basic code
When you suspend execution of Microsoft Visual Basic code, the code is still running but is paused between running statements. While your code is suspended, you can do debugging tasks such as checking current variable values and running each line of code one at a time. To make Microsoft Visual Basic pause your code, you can set a breakpoint.
To clear a breakpoint, move the insertion point to the line of code on which the breakpoint has been set, and then click Toggle Breakpoint on the Debug toolbar.
To resume running the code, click Run Sub/UserForm on the Run menu.
Note You can also suspend code by adding a Stop statement to a procedure or by pressing CTRL+BREAK while the code is running.
Step through Visual Basic code
Stepping through your Visual Basic code can help you identify where an error is occurring. You can see whether each line of code produces the results you expect.
How?
When you suspend execution of Microsoft Visual Basic code, the code is still running but is paused between running statements. While your code is suspended, you can do debugging tasks such as checking current variable values and running each line of code one at a time. To make Microsoft Visual Basic pause your code, you can set a breakpoint.
To clear a breakpoint, move the insertion point to the line of code on which the breakpoint has been set, and then click Toggle Breakpoint on the Debug toolbar.
To resume running the code, click Run Sub/UserForm on the Run menu.
Note You can also suspend code by adding a Stop statement to a procedure or by pressing CTRL+BREAK while the code is running.
Microsoft Access displays the line of code where execution is suspended.
To step through each line of code and into the code in
a procedure called by another procedure, click Step Into
on the Debug toolbar.
To step through each line of code but run as a unit any
procedure that is called, click Step Over
on the Debug toolbar.
To run the code that precedes the current line of code, and then break so you can step through each line of code, click Run To Cursor on the Debug menu.
To run the rest of the current procedure, and then return
to the next line of code in the preceding procedure in the call tree,
click Step Out on the toolbar.
Note You can use Step Into
without suspending code execution. In the
Visual Basic
Editor Code
window, place your cursor in the procedure you want to step through, and
click Step Into
on the toolbar.
You can alternate between these types of stepping. The type of stepping you do depends on which portions of code you want to analyze.
Perform a quick watch while debugging Visual Basic code
How?
When you suspend execution of Microsoft Visual Basic code, the code is still running but is paused between running statements. While your code is suspended, you can do debugging tasks such as checking current variable values and running each line of code one at a time. To make Microsoft Visual Basic pause your code, you can set a breakpoint.
To clear a breakpoint, move the insertion point to the line of code on which the breakpoint has been set, and then click Toggle Breakpoint on the Debug toolbar.
To resume running the code, click Run Sub/UserForm on the Run menu.
Note You can also suspend code by adding a Stop statement to a procedure or by pressing CTRL+BREAK while the code is running.
Microsoft Access displays the line of code where execution is suspended.
Microsoft Access displays the Quick Watch dialog box, where you can see the expression and the current value of the expression. Click Add in the dialog box to add the expression to the list of watch expressions in the Watch window of the Microsoft Visual Basic Editor.
Trace Visual Basic procedure calls while debugging Visual Basic code
When you suspend execution of Visual Basic code while debugging the code, you can use the Calls dialog box to view a list of procedures that have been started but not completed.
How?
When you suspend execution of Microsoft Visual Basic code, the code is still running but is paused between running statements. While your code is suspended, you can do debugging tasks such as checking current variable values and running each line of code one at a time. To make Microsoft Visual Basic pause your code, you can set a breakpoint.
To clear a breakpoint, move the insertion point to the line of code on which the breakpoint has been set, and then click Toggle Breakpoint on the Debug toolbar.
To resume running the code, click Run Sub/UserForm on the Run menu.
Note You can also suspend code by adding a Stop statement to a procedure or by pressing CTRL+BREAK while the code is running.
Microsoft Access displays the line of code where execution is suspended.
Microsoft Access displays the most recently called procedure at the top of the list, followed by the next most recent procedure call, and so on. To display the statement that calls the next procedure in the list, click Show.
Add, modify, or delete a watch expression in the Watch window of the Microsoft Visual Basic Editor
Add a watch expression
Instead of typing the expression, you can also select an expression in the Code window and drag it to the Watch window.
Note Select the narrowest scope that fits your needs. Selecting all procedures or all modules could slow down code execution.
To display the value of the watch expression, click Watch Expression.
To pause execution if the expression evaluates to True, click Break When Value Is True.
To pause execution if the value of the expression changes, click Break When Value Changes.
When you run the code, the Watch window shows the value of the expression you set.
Modify a watch expression
Select the expression in the Watch window.
Click Edit Watch on the Debug menu.
Delete a watch expression
Click Delete in the Edit Watch dialog box.
Disable syntax checking
Microsoft Visual Basic automatically checks the code you type in the Code window of the Microsoft Visual Basic Editor for syntax errors as you type it. You can disable this feature.
- On the Tools menu, click Options.
- Click the Editor tab.
- Under Code Settings, clear the Auto Syntax Check check box.
Ignore error handling
When you add an On Error statement to a Visual Basic procedure, Visual Basic automatically branches to an error-handling routine when an error occurs. You may want to ignore a procedure's error-handling code in some circumstances รน for example, while you're debugging the procedure.
When you check this option, you'll automatically enter Break mode when an error occurs, regardless of error handling.