Access.2007.VBA.Bibl..

(John Hannent) #1

Save Word document:


appWord.ActiveDocument.SaveAs strSaveNamePath

With appWord
.ActiveWindow.WindowState = wdWindowStateNormal
.Visible = True
.Activate
End With

ErrorHandlerExit:
Exit Sub

ErrorHandler:
If Err = 429 Then

Word is not running; open Word with CreateObject:


Set appWord = CreateObject(Class:=”Word.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If
End Sub

Word Mail Merge ..........................................................................................

You can link a Word merge document directly to an Access table or query; however, there are some
drawbacks to this method. The merge document won’t open unless the Access database is available
and is in the same location as when the merge data source was selected. Because of this limitation,
when using mail merge I prefer to export the Access data to a text file, and assign the newly created
text file as the merge document’s data source. This means that the document can be opened with-
out Access being available, and without the need to establish a link to a database.


Mailing Labels

Sheets of mailing labels are very suitable for mail merge; you can select three types of Avery mailing
labels (Mail Merge type) from the Select Document combo box on frmMergeToWord. If you select
the Avery 5160 Labels (Mail Merge) document, you will get a Word document like the one shown
in Figure 6.23.


The Avery labels documents look (and work) exactly the same whether produced by mail merge or
the TypeTextmethod, so I prefer to use the TypeTextmethod, because it is much simpler to
set up a plain labels document than a mail merge document; all you have to do is create a labels-
type document in Word, whereas creating a mail merge document requires manually linking to a
data source and inserting merge fields.


Working with Word Documents and Templates 6

Free download pdf