Datasheet

Book VIII
Chapter 1
What the Heck
Is VBA?
Using the Visual Basic Editor
585
Referring to objects and collections
Objects in the object model all have a syntax that works like this: You start
with the largest, most encompassing object, and work your way down to the
most specific object, property, or method. Sort of like a path to a filename,
as in
C:\My Documents\MyFile.doc, where you start with the largest
container (disk drive
C:), down to the next container (the folder named My
Documents
), and then to the specific file (MyFile.doc).
For example, the
Application object refers to the entire Access pro-
gram. It includes a
CurrentProject object. If you were to look up the
CurrentProject object in the Object Browser and view its Help window,
you see
CurrentProject houses several collections, including one named
AllForms. The AllForms collection contains the name of every form in the
current database.
The
AllForms collection, in turn, supports a Count property. That property
returns the number of forms in the collection. Say that you have a database
open and that database contains some forms. If you go to the Immediate
window and type
? Application.CurrentProject.AllForms.Count
and then press Enter, the Immediate window displays a number matching
the total number of forms in the database.
Figure 1-14:
Help for the
DoCmd
object.
38_036494 bk08ch01.qxp 11/17/06 8:34 AM Page 585