Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 22: Integrating Access with Other Applications .............................................................


791


though, many highly productive tasks can be performed using only a fraction of the objects
exposed in an application’s Automation interface.

Creating Automation references
Applications supporting Automation provide information about their exposed objects in an object
library. The object library contains information about an application’s properties, methods, and
classes. Each object in an application’s Automation interface supports some aspect of the application’s
features. For example, Word’s Selection object represents a the current selection in a window or
pane, while the Bookmarks collection provides handles to all the bookmarks within a document.

When writing Automation code, you use object variables to represent the objects exposed by the
Automation server’s interface. Within your VBA code, you treat the object variable as if it were a
literal instance of the Automation server. In the “Creating an instance of a Word object” section,
later in this chapter, you’ll see code that declares an object variable named WordObj. Once this
variable has been connected to Microsoft Word, WordObj acts as if it were Microsoft Word. In
other words, WordObj acts as a proxy for Microsoft Word within your code. In most cases, you
begin by referencing the server application’s object library. Referencing the library makes the
exposed Automation interface accessible to your application. As you’ll soon see, referencing an
object library eases the process of writing VBA code against the interface. The reference also makes
it possible to view the Automation interface in the VBA Object Browser.

Adding an object library reference is fairly easy. From the VBA code editor, choose Tools ➪
References to open the References dialog box (see Figure 22.1). Each item in the References dialog
represents an object library that is installed on the local computer (not all object libraries support
Automation, however).

In Figure 22.1 notice that each item in the references list includes a checkbox. The items at the top
of the list with filled check boxes (like Microsoft ActiveX Data Objects) are already referenced by
the current application. In fact, Access requires references to several object libraries for its normal
operation.

Note
Object libraries are routinely added to the files on a computer when the Automation server is installed. In fact,
an Automation server’s object library is almost certainly used by the server application in its normal operation.
The objects, properties, and methods you use when automating Microsoft Word are exactly the same objects,
properties, and methods that Word uses every time you work with it.


Use the scrollbar at the right side of the references list to locate the desired object library, and click
its check box to add it as a reference to the current application.

Not all object libraries have obvious names. Sometimes the library name in the references list is not
what you expect. Often a likely-looking library name turns out to be something entirely different.
To further complicate things, some applications support more than one object library. In these
cases, it is very helpful to have a good example to follow or, at least, to have good documenation of
an application’s object library.
Free download pdf