Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 14: Debugging Your Access Applications


535


There are also some problems associated with MsgBox statements:

l There is nothing about the MsgBox statement to prevent it from popping up in front of an
end user, causing all kinds of confusion and other problems.

Caution
Never, ever forget to remove all MsgBox statements from your code before shipping to end users!


l Message boxes are modal, which means you can’t flip to the code editor window or
Immediate window (discussed in the “Running code with the Immediate window” section,
later in this chapter) to examine the value of variables or examine the code underlying the
application. Using the MsgBox statement is an all-or-nothing proposition (with the one
exception described in the “Compiler directives” sidebar).

A refinement of the MsgBox technique is to use compiler directives to suppress the MsgBox statements,
unless a special type of constant has been set in the code or within the Access environment. Examine
the code in the following figure. Notice the #Const compiler directive above the MsgBox statement
and the #If and #End If directives surrounding the MsgBox statement.

Compiler directives make it easy to include or exclude blocks of code from an application.

All the keywords beginning with the pound sign (#) are seen only by the VBA compiler. These key-
words (#Const, #If, #Else, and #End If) constitute directives to the VBA compiler to include (or
exclude) certain statements in the compiled version of your project.

continued

Compiler directives

Free download pdf