Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 14: Debugging Your Access Applications


547


Figure 14.23 shows the Watches window in action. The sSQL variable is displayed for all proce-
dures in all modules.

FIGURE 14.23

The Watches window reveals all of a variable’s details.


Tip
The Watches window can “float” or be docked at any side of the VBA editor window. If you don’t like the
Watches window’s current position, use its title bar to drag it to another location. As you drag the window to a
docking position, a gray rectangle appears where Access thinks you want to dock the window. Just release the
mouse button when you have the window positioned in its new location, and Access will either dock the win-
dow or leave it floating freely, as you directed. The Watches window will be in the same position the next time
you open the VBA editor window.


If you don’t like the “docking” behavior, right-click anywhere within the body of the Watches window and
deselect the Dockable option.


Using conditional watches
Although watching variables in the Locals window or Watches window can be entertaining, you
can spend a lot of unproductive time hoping to see something unexpected happen. You’ll probably
find it much more efficient to set a conditional watch on a variable, and instruct the VBA engine to
break when the condition you’ve established is met.

The Add Watch dialog box (see Figure 14.24) accepts a Boolean (true or false) expression, such as
CustomerId=99 in the text box near the top. You specify where in the application (which proce-
dures and which modules) the expression is applied, and you tell Access what you want the VBA
engine to do when the expression is evaluated. For my purposes, I want execution to break when
the expression CustomerID=99 is True.

The conditional watches you set up through the Add Watch dialog box are added to the Watches
window. The watch expression appears in the Watches window’s Expression column.

You can use conditional watches in other ways, too, such as using compound conditions (X =
True And Y = False), and forcing a break whenever a value changes from the value set in the
Expression text box. The small example illustrated in Figure 14.22 only hints at the capabilities
possible with conditional watches.
Free download pdf