If you have a reference set only to the ADO object model, this code won’t even compile, and you
will get a “User-defined type not defined” error. If you have references set to both object models,
and the ADO reference is first, you will get a different error, this time on the line with the
FindFirstmethod reference: “Method or data member not found.” If you have just a DAO refer-
ence, or the DAO reference is positioned above the ADO reference, the code will compile and run.
If you get a “User-defined type not defined” or “Method or data member not found”
error message when compiling code, this is almost always an indication of a missing or
incorrect object model version reference.
A more subtle problem could result from an ambiguous declaration of the Field object. There is a
Field object in both the ADO and DAO object models, but it has different properties and methods
in each object model (see Figures 5.5 and 5.6), so a line of code referencing a Field property could
lead to an error if that property is not supported in the object model that is being used.
Although the Access 2007 interface is very different than the interface you might be
used to, which has remained pretty much the same from Access 2000 through Access
2003, the Visual Basic (Modules) window is unchanged, except that the mouse wheel now works
(about time!).
NOTENOTE
TIPTIP
Part II Writing VBA Code to Exchange Data between Office Components
Using the Object Browser
T
he Object Browser is a very useful tool for examining object models and their components. It can
be opened from a Visual Basic window in Access, Word, Excel, or Outlook from a command on
the View menu or by pressing the F2 key. The drop-down list at the top-left lists the available object
libraries (corresponding to the references you have set in the database); the lower drop-down list is
a search box where you can enter the name of an object model component or attribute to search for;
clicking the binoculars button starts the search, and the results are displayed in the Search Results
box, as in the following figure. The Classes list shows the members of the selected object library, and
the Members of ‘Field’ list shows the attributes (properties, methods, and events) of the selected
object model component.
If you click the yellow question mark button, you will usually get a Help topic for the selected object
or attribute, but you can’t depend on this — sometimes all you get is a blank Help window. In the
case of ADO, in previous versions of Access, if you set a reference to the most recent version of this
library (2.8 at that time), you would get blank Help pages; if you set a reference to ADO 2.5, how-
ever, you would get the appropriate Help topic. In Access 2007, if you set a reference to the highest
version of ADO (6.0), you will get an “Unable to display Help” error message on clicking the Help
button. If you set a reference to ADO 2.5, clicking the Help button opens the “Browse Access
Developer Help” screen, rather than the specific Help topic for the selected object model compo-
nent or attribute.
Figure 5.5 shows the attributes of the ADO Field object in the Object Browser.