Check for the template in the selected template folder, and exit if it is not found:strTestFile = Nz(Dir(strWordTemplate))
Debug.Print “Test file: “ & strTestFile
If strTestFile = “” Then
MsgBox strWordTemplate & “ template not found; “ _
& “can’t create document”
GoTo ErrorHandlerExit
End IfCall the appropriate procedure depending on the selected merge type:strMergeType = Nz(Me![cboSelectDocument].Column(2))
If Right(strWordTemplate, 1) = “x” Then
strExtension = “.docx”
Else
strExtension = “.doc”
End IfSelect Case strMergeTypeCase “Doc Props”
Call MergeDocProps(strWordTemplate, strExtension)Case “Bookmarks”
Call MergeBookmarks(strWordTemplate, strExtension)Case “TypeText”
Call MergeTypeText(strWordTemplate, strExtension)Case “Mail Merge”
Call MailMerge(strWordTemplate, strExtension)End SelectErrorHandlerExit:
Exit SubErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExitEnd SubIf a document of the Doc Props merge type is selected, the MergeDocProps procedure is called.
This procedure first sets a reference to the handy ItemsSelected collection of the ListBox (this col-
lection includes only the rows selected in the ListBox), then iterates through the collection, creat-
ing a new Word document for each contact record.Part II Writing VBA Code to Exchange Data between Office Components