Use the Immediate window of the Microsoft Visual Basic Editor to check the results of a line of Microsoft Visual Basic code. You can use the Immediate window to check the value of a control, field, or property; to display the result of an expression; or to assign a new value to a variable, field, column, or property. The Immediate window is a kind of scratchpad window in which statements, methods, and Sub procedures are evaluated immediately.
- Do one of the following:
To display the Immediate window at any time in Microsoft Access, press CTRL+G.
To use the Immediate window at a certain point during execution of the code, suspend execution at that point and then click Immediate Window on the Debug toolbar.
- Do one of the following:
Type a statement, method, Function, or Sub procedure call in the window, and then press ENTER.
View the results of an expression in the Immediate window by entering the Print method of the Debug object, followed by the expression. You can use a question mark (?) as shorthand for the Print method.
For example, Microsoft Visual Basic displays the value returned by the FirstOfNextMonth custom function if you type either of the following lines in the Immediate window:
Debug.Print FirstOfNextMonth() ? FirstOfNextMonth()
Change how Visual Basic code is displayed in the Code window
You can change the color, font, font size, and tab width used when you type Visual Basic code in the Code window. You can also specify whether the entire module is displayed (default) or each procedure is displayed individually in the Code window, and set various additional options for working in the Code window.
- On the Tools menu, click Options.
- Set the appropriate options.
Display a list of relevant objects, properties, and methods in the Visual Basic Editor
When Auto List Members is selected, Microsoft Access assists you in completing statements while you're writing Visual Basic code.
- On the Tools menu, click Options.
- Click the Editor tab.
- Under Code Settings, make sure Auto List Members is selected.
Note To make the list disappear, press ESC.
Display syntax information in the Visual Basic Editor
You can set the Visual Basic Editor to display syntax information in the Code window. When you type a method or the name of an existing procedure followed by a space or opening parenthesis, a tip automatically appears giving syntax information about the method or procedure, such as the arguments for you to specify.
- On the Tools menu, click Options.
- Click the Editor tab.
- Under Code Settings, make sure Auto Quick Info is selected.
Display the value of a variable or expression in the Visual Basic Editor when code is suspended
You can check the value of a variable or an expression while code is suspended. Rest the mouse pointer on a variable or expression to display its current value.
- On the Tools menu, click Options.
- Click the Editor tab.
- Under Code Settings, make sure Auto Data Tips is selected.
Display the value of variables in the Locals window of the Visual Basic Editor
In the Locals window, Microsoft Access automatically displays the name, current value, and type of all the variables and objects in the current procedure. The values in the Locals window are updated each time you suspend code execution. You can change the value of a variable in the Locals window by selecting the existing value and entering the new value.
- Suspend execution of 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.
- In the Visual Basic Editor, move the insertion point to a line of code that isn't already a breakpoint or declaration.
- Click Toggle Breakpoint on the Debug toolbar.
- Do one of the following:
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.
- Click Locals Window on the View menu.