Access.2007.VBA.Bibl..

(John Hannent) #1
For intIndex = 0 To intRows
lst.Selected(intIndex) = False
Next intIndex

ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit

End Sub

The cmdSelectAll_Clickprocedure, run from the Select All Names command button, selects
all the rows in the listbox; its code is similar, setting the Selectedvalue to Trueinstead of
False.


Clicking the Clear All Selections command button clears any selections you have made in the list-
box; clicking the Create Documents command button starts the merge, calling one of four proce-
dures, depending on the merge type.


Word Bookmarks ..........................................................................................

If you select the Contact Letter with Envelope (Bookmarks) template from the Select Document
combo box on frmMergeToWord, you will get a set of individual letters, one to each selected con-
tact, with bookmarks filled with Access data. One of these letters is shown in Figure 6.20 (I made
bookmarks visible so you can see their locations; note the gray I-bars).


The MergeBookmarksprocedure (listed next) is basically similar to the MergeDocProps
code listed in an earlier section; the difference is that instead of working with the
CustomDocumentProperties collection, it works with the Bookmarks collection, writing
information from either variables or the listbox to named bookmarks in the newly created
Word document:


Private Sub MergeBookmarks(strWordTemplate As String, _
strExtension As String)

On Error GoTo ErrorHandler

strLongDate = Format(Date, “mmmm d, yyyy”)
strShortDate = Format(Date, “m-d-yyyy”)
strDocsPath = GetContactsDocsPath()
Debug.Print “Docs path: “ & strDocsPath

Working with Word Documents and Templates 6

Free download pdf