Access.2007.VBA.Bibl..

(John Hannent) #1
In code for this chapter’s sample database, the assumption is that the Word templates
are located in the default folder, which is C:\Users\User Name\AppData\Roaming\
Microsoft\Templates for Windows Vista or C:\Documents and Settings\User Name\Application
Data\Microsoft\Templates for Windows XP. For a more flexible method of setting the Templates
folder, see Chapter 6.

The form frmContacts in the sample Access to Word database displays contacts located in the
U.S.A. The form, shown in Figure 2.6, has three buttons, each of which creates a letter to the
selected contact using a different method.

FIGURE 2.6
The Contacts form with buttons to create Word letters.

The code for creating a document using bookmarks is listed as follows:

Private Sub cmdBookmarks_Click()

On Error GoTo ErrorHandler

Dim appWord As Word.Application
Dim doc As Word.Document
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strTemplatePath As String
Dim strTemplateName As String
Dim strTemplateNameAndPath As String
Dim lngContactID As Long
Dim strRecipientName As String
Dim strRecipientAddress As String

CROCROSSSS-REF-REF


Part I The Office Components and What They Do Best

Free download pdf