Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 13: Accessing Data with VBA Code


499


RecordCount is a convenient way to determine whether a recordset contains any records at all.
The only issue with RecordCount is that, on large recordsets, RecordCount penalizes perfor-
mance. The Recordset object actually counts the number of records it contains, halting execu-
tion until the count is complete.

A much faster way to detect an empty recordset is determining whether EOF and BOF are both
True:

If rs.BOF = rs.EOF Then
Debug.Print “No records to process”
Exit Sub
End If

BOF and EOF are the same value only when the recordset contains no records. (In this case, both
are True at the same time.)

Cross-Reference
ADO Recordset objects include many capabilities not covered in this chapter. Many of the remaining
recordset features are covered in Chapter 25, while others are documented in various other chapters of this
book. The ADO Recordset object is a powerful tool for Access developers, and deserves careful study in a
variety of contexts.


Understanding DAO Objects


Data Access Objects (DAO) is the older Access data access object model. DAO has been included
in Access since the very beginning, and, although not the focus of this book, it’s frequently used in
Access applications.

Unlike ADO, DAO objects are arranged in a hierarchical fashion. Certain objects are subordinate to
other objects, and they can’t exist without an instance of the superior object. The father of all DAO
objects is DBEngine. DBEngine is at the head of the DAO family tree, and all other objects are
descendants of DBEngine (see Figure 13.13).

Each of the most frequently used DAO objects is described later in this section.

Generally speaking, the DAO hierarchy closely follows the arrangement of Access database objects.
For example, an Access table (which is a TableDef object) contains fields (each of which is a
Field object). A field has a set of properties you use to specify the details of its data type, the
default value, validation rules, and so on.

Note
For clarity’s sake, the set of properties associated with each DAO object is left out of Figure 13.13. But, you
can safely assume that every object in Figure 13.13 includes an attached set of property objects.

Free download pdf