Access SQL
Access SQL
MAY TUTOR ■
ACCESS SQL
easing
into sql
T h e re’s good reason for Access pro g ra m m e rs to learn SQL. The Access query design
grid lets you construct complicated SQL st at e m e n ts with minimal diffi c u l t y. Here’ s
h ow to keep your queries error and bug fre e .
astering Access SQL (Structured such, prone to logic errors and typos, so let In many cases, the resulting statement will
■ MAY TUTOR
ACCESS SQL
MAY TUTOR ■
ACCESS SQL
sion includes the actual name of the data source view this query’s SQL statement, shown in Fig- your changes when prompted. The control will
and the criteria string, not the variables shown ure 2, by choosing SQL View from the View update accordingly.
in the code listing above. button at the far left of the toolbar. You can SQL can be difficult to work with; even the
Not only is this solution easier, but you avoid also see the results of the query by choosing experts occasionally fret over a statement. For-
introducing typos. Don’t wait until you have a Datasheet View. tunately, Access offers a number of tools to
problem with a SQL statement, though; get in As you can see, this builder is flexible – you make the task easier. The query design grid
the habit of adding this functionality to your can view three different forms of the same gives you an easier way to create SQL state-
code so it’s available when you need it. query. You can bounce back and forth between ments than trying to create them from scratch.
the builder, the SQL statement, and the results In addition, you can debug statements by copy-
QUICK RESULTS WITH THE QUERY BUILDER until you get the statement just right, at which ing evaluated statements from the Immediate
Access SQL isn’t limited to queries and VBA time you simply close the builder and save window to the query design grid.
modules; controls often use a SQL statement
instead of a saved query as the Row Source
property. Fortunately, you don’t have to create
the appropriate statement from scratch; you
can use the SQL statement query builder. (We’ll
show you how to access this builder in just a
minute.) In the open builder, you’ll choose
fields and express criteria in the query design
grid, just as you would in a normal query. The
builder then converts your work into a SQL
statement. You don’t actually have to know Figure 1: The SQL Statement Query Builder launches a query design grid.
SQL at all.
Let’s take a look at an example. Open in
Design View any form that contains a combo
or list box, or open a blank form and add a
combo or list box. Double click the combo or
list box to open its property sheet, and click the
Build button that appears when you select the
Row Source property field. This launches the
SQL statement query builder, which is a sim-
ple query design grid. Modify the grid as you
would a query. (If you’re working with an
existing control, the grid will display an equiv-
alent sql statement in the query design grid.)
Figure 1 shows a simple expression that will
display a list of concatenated fields – FirstName
and LastName. In other words, the combo or
Figure 2: The query in Figure 1 and the SQL statement here represent the same question.
list control will display a list of names. You can
See this month’s reader response card and you could win one of these fantastic prizes.
WIN!