15.4. Exchanging Information with Microsoft Word

Access has some wonderful reporting features. You can sort, group, filter, and even perform sophisticated combinations of those operations using VBA. If you can create such sophisticated reports in Access would you even need Word? Well, the simple answer is yes. There are a number of tasks you can't perform in Access and still others that you might simply want to transfer into Microsoft Word. For example, the first code sample we'll build starts a mail merge within Word from your Access data. While you can create a letter within Access, it must be done by someone with adequate permissions on your database. You probably don't want to give every user of your application permissions to create and modify reports. Many users probably have no desire to ever modify a report. Working around this limitation is pretty simple. Provide your users with a boilerplate mail merge document in Word and allow them to customize the mail merge document to suit their needs. Then they can simply initiate the mail merge from within Access.

Figure 15.8. Figure 15-8

You can write the mail merge code in two ways. The first, and simplest way, is to use Access VBA to simply define your data source and open the merge document. The second way is to use VBA to perform every step of the mail merge process. We'll examine both methods in this section.

15.4.1. The ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.