Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 11: Mastering VBA Data Types and Procedures .............................................................


419


One particularly powerful use of the continuation character is illustrated later in this chapter (in
Figure 11.14). In Figure 11.14, a long SQL statement is split across a number of lines of code. All
that’s needed on each subsequent line is the concatenation character (&) and as much of the string
as you want to add on the line. Each portion of the SQL statement must be surrounded by double
quotes, and you must preserve spaces between words in the statement. Splitting long SQL state-
ments this way makes it easy to see what’s in the statement and, therefore, what fields end up in
the resulting recordset.

Most often, however, continuation characters are used to break up long, complex statements.
Figure 11.2 shows an example of this use of the continuation character. In this figure, a long VBA
statement that opens a new recordset is split into five lines of code. The continuation characters are
placed after the commas separating the elements contained in the complex statement, making the
statement easier to read and understand.

FIGURE 11.2

Use the continuation character to split long strings into multiple lines.


Continuation characters can be inserted almost anywhere within a VBA statement. (You can’t split
individual words in a statement with continuation characters.) It makes sense, therefore, to insert
the continuation character sequence in places (such as in Figure 11.2) that add to the readability of
long statements. In Figure 11.2, inserting a continuation after each comma breaks the statement
into logical sections. Putting continuations anywhere else in this statement would make it harder
to read.

Another powerful feature of the Access code editor is the text colors used to set aside comments,
keywords, and identifiers. Although it’s not obvious in this book’s figures, the comments in Figure
11.1 and Figure 11.2 appear in a green font, while the VBA keywords like Function, Const,
and If are blue. Identifiers like conObjStateClosed and conDesignView, as well as the pro-
cedure name IsLoaded in Figure 11.1, are black.
Free download pdf