Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 6.24

The Contact List filled with merged data from Access.


If a merge document with the Merge Data.txt data source is open, if you try to create
another merge document bound to the same data source, you will get an error message
saying that Merge Data.txtalready exists, and you won’t be able to continue. To prevent this from
happening, the mail merge code closes the original merge document after merging the data to a new
document.

The MailMergeTextFileprocedure is listed as follows. This procedure first fills an Access table
with data from the ItemsSelected collection of the ListBox, and then exports the data from that
table to a text file, Merge Data.txt, which is used as the data source for the mail merge docu-
ment. The merge is executed to a new document (so the document can be opened later, without
needing the data source) and saved to a name picked up from the template’s Title field and the
date, formatted with dashes to avoid file name problems:

WARNINWARNINGG


Working with Word Documents and Templates 6

Free download pdf