473
CHAPTER
Accessing Data with
VBA Code
IN THIS CHAPTER
Examining SQL statements
Working with Access data
Examining the ADO object
model
Looking at DAO objects
Updating a table with VBA
code
D
ata access and data management are at the core of any database
application. Although you can do a fine job building applications
with bound forms, using Visual Basic for Applications (VBA) code
to access and manipulate data directly provides far greater flexibility than a
bound application can. Anything that can be done with bound forms and
controls can be done with a bit of VBA code using ActiveX Data Objects
(ADO) or Data Access Objects (DAO) to retrieve and work with data.
The VBA language offers a full array of powerful commands for manipulating
records in a table, providing data for controls on a form, or just about any-
thing else. This chapter provides some in-depth examples of working with
procedures that use SQL and ADO to manipulate database data.
On the CD-ROM
In the Chapter13.accdb database, you’ll find a number of forms to use as a
starting point and other completed forms to compare to the forms you change
in this example.
Understanding SQL
Many of the VBA procedures that you write for working with Access data
utilize Structured Query Language (SQL) statements to retrieve data from a
database, add new data to a database, or update records in a database. When
you use the Access Query Designer to create a query, Access converts the
query’s design into a SQL statement. The SQL statement is what Access actu-
ally executes when the query runs.
SQL is a fairly standard language for querying and updating database tables,
and it’s used by many relational databases. Although Access SQL does not