Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 14: Debugging Your Access Applications


539


One of the most basic uses of the Immediate window is to run code, such as built-in functions, or
subroutines and functions that you’ve written. Figure 14.14 shows several examples that have been
run in the Immediate window.

FIGURE 14.14

Running code from the Immediate window is a common practice.


The first example in Figure 14.14 shows the same convention used to run a function
(UsingDebugDotPrint) that’s been added to the VBA project. You see the result of the function’s
execution (a long SQL statement), as long as the function is declared with the Public keyword,
and any arguments required by the function are provided.

The Now() function has been run from the Immediate window, returning the current date and
time. The question mark (?) in front of the Now() function name is a directive to the Immediate
window to display (or print) the value returned by the Now() function.

The third example in Figure 14.14 (SomeProcedureName) shows calling a subroutine from the
Immediate window. Because subroutines don’t return values, the question mark is not used. The
Call keyword is optional when calling subroutines, but it’s often included for clarity.

Suspending execution with breakpoints
You suspend execution by setting a breakpoint in the code. When Access encounters a breakpoint,
execution immediately stops, allowing you to switch to the Immediate window to set or examine
the value of variables.

Setting a breakpoint is easy. Open the code window and click on the gray Margin Indicator bar to
the left of the statement on which you want execution to stop (see Figure 14.15). Alternatively,
position the cursor on the line and click on the Breakpoint ribbon button. The breakpoint itself
appears as a large brown dot in the gray bar along the left edge of the code window and as a brown
highlight behind the code. The text of the breakpoint statement appears in a bold font.

Tip
You can change all these colors and font characteristics in the Modules tab of the Options dialog box.

Free download pdf