Microsoft Access 2010 Bible

(Rick Simeone) #1

Part II: Programming Microsoft Access


538


Unlike the MsgBox statement, you don’t have to do anything special to suppress the Debug.
Print output from the user interface. The output of Debug.Print only goes to the Immediate
window, and because end users never see the Immediate window, you don’t have to worry about a
user encountering debug messages.

The problems with Debug.Print are obvious from Figure 14.12. Long strings don’t wrap in the
Immediate window. Also, the Immediate window must be visible in order for you to view its out-
put. But these limitations are relatively harmless and you’ll frequently use Debug.Print in your
applications.

Note
Some people have reported that excessive numbers of Debug.Print statements can slow an application.
Even though the Immediate window is not visible, Access executes the Debug.Print statements that it finds
in its code. You may want to consider surrounding each Debug.Print statement with the compiler directives
described in the “Compiler directives” sidebar to remove them from the end user’s copy of the application.


Using the Access Debugging Tools


Microsoft Access features a full complement of debugging tools and other capabilities. You use
these tools to monitor the execution of your VBA code, halt code execution on a statement so that
you can examine the value of variables at that moment in time, and perform other debugging tasks.

Running code with the Immediate window
Open the Immediate window (also called the Debug window) by choosing View ➪ Immediate or
by pressing Ctrl+G. You can open the Immediate window any time (for example, while you’re
working on a form’s design). You’ll sometimes find it useful to test a line of code or run a proce-
dure (both of which are supported by the Immediate window) while you’re working on a form or
report.

The Immediate window is shown in Figure 14.13. The Immediate window permits certain interac-
tivity with the code and provides an output area for Debug.Print statements. The basic debug-
ging procedures include stopping execution so that you can examine code and variables,
dynamically watching variable values, and stepping through code.

FIGURE 14.13

Get to know the Immediate window! You’ll use it a lot in Microsoft Access.

Free download pdf