Access.2007.VBA.Bibl..

(John Hannent) #1

The code then sets a reference to the Word CustomDocumentProperties collection of the newly
created document, and sets each document property to the value in a column of the current row
from the ListBox. A save name is created, including the document title, contact name, company
name, and date, and the document is saved:


Private Sub MergeDocProps(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

Check that at least one contact has been selected:


Set lst = Me![lstSelectContacts]

If lst.ItemsSelected.Count = 0 Then
MsgBox “Please select at least one contact”
lst.SetFocus
GoTo ErrorHandlerExit
End If

intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count

For Each varItem In lst.ItemsSelected

Check for required address information:


strTest = Nz(lst.Column(5, varItem))
Debug.Print “Street address: “ & strTest
If strTest = “” Then
Debug.Print “Skipping this record -- no address!”
GoTo ErrorHandlerExit
End If

strTest = Nz(lst.Column(1, varItem))
Debug.Print “Contact name: “ & strTest
If strTest = “” Then
Debug.Print _
“Skipping this record -- no contact name!”
GoTo ErrorHandlerExit
End If

strContactName = _
Nz(lst.Column(1, varItem))
strCompanyName = _
Nz(lst.Column(7, varItem))

Working with Word Documents and Templates 6

Free download pdf