Access.2007.VBA.Bibl..

(John Hannent) #1
If you don’t want to create multiple documents, you can eliminate the Do...Loopstatement and
overwrite an existing file with the same name, if there is one.

Sending a Word Letter to Multiple Access Contacts

When you need to select a group of recipients for a Word letter, set of labels, or another document,
you need a different interface. The form frmMergeToWord has a combo box for selecting a Word
template, and a multi-select ListBox for selecting one or more contacts as recipients (see Figure 6.17).

FIGURE 6.17
A form for selecting a document and recipients for creating Word documents filled with Access data from
multiple contact records.

The Select Document combo box list shows the merge type in the second column (see Figure 6.18).

The procedure on the cmdMerge button’s Click event first determines that a template has been
selected, and that the template can be found in the Contact Templates folder (this folder is set on
the database’s main menu). Next, the merge method is picked up from the third column of the
combo box’s list (the first column is not displayed; it contains the file name of the selected docu-
ment, for use in code).

Because some of the merge documents are Word documents, and some are templates, and some are
in Word 2007 format and others in Word 97/2003 format, there is an If...Thenstatement in
the procedure that examines the original document’s extension, and creates the appropriate save
document extension for use as an argument for the called procedures.

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf