Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 22: Integrating Access with Other Applications


793


Referencing an object library means that you can use early binding to attach to objects exposed by
the library. Once the object library is referenced, the VBA code editor uses IntelliSense — particu-
larly Auto List Members and Auto Quick Info — to help you write effective code against the object
library’s contents.

For example, assume you’ve referenced the Microsoft Word libary, and the following statements
appear in a VBA procedure:

Dim WordObj As Word.Application
Set WordObj = New Word.Application

The first statement declares an object variable (WordObj) as a Word.Application object type.
Word refers to the referenced object library, and Application is one of the exposed object
classes within the library.

The second statement instantiates the object variable. As this statement executes, VBA builds an
instance of the Word.Application object in the computer’s memory; this is the application’s
proxy, discussed in the “Creating Automation References” section, earlier in this chapter. Once the
object instantiation is complete, VBA code is able to direct the Application object to perform
work on behalf of the VBA project.

This process is called early binding because the Word.Application object is explicitly declared
and instantiated. The object type is known before the application is even started. In the next sec-
tion, you’ll read about late binding, where the type of object is not known until the code actually
executes.

Caution
For this chapter, you need to make sure that several object libraries are referenced. You may not initially have
all four of the following references checked:


Microsoft DAO Object Library
Microsoft ActiveX Data Objects
Microsoft Word Object Library
Microsoft Office Object Library

If these libraries aren’t active (or, visible at the top of the list), find them in the selection list box by scrolling to
them, and verify that they’re checked in the references list.


After you reference an Automation object library, you explicitly declare object variables from the
referenced library. The VBA IntelliSense help feature displays the objects contained within the
library as you type, as shown in Figure 22.2. After you select an object and enter a period,
IntelliSense shows you the available classes within the object (see Figure 22.3).
Free download pdf