Save the newly created merge document:
.ActiveDocument.SaveAs strSaveNamePath
Close the master merge document:
.Documents(strDocName).Close _
SaveChanges:=wdDoNotSaveChanges
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
Summary ..........................................................................................................................
Now you know how to export Access data to various types of Word documents, both in the inter-
face and in VBA code, you can produce highly formatted Word documents filled with Access data.
Microsoft promotes mail merge, but in my opinion it is best to avoid this method (especially in
Office 2007 and Windows Vista), because of the problems it has with security features. With the
three other techniques covered in this chapter, you will know how to produce almost any type of
document using other methods, and avoid the problems with locked or unavailable databases
when using mail merge when it is needed.
Part II Writing VBA Code to Exchange Data between Office Components