strLongDate = Format(Date, “mmmm d, yyyy”)
strShortDate = Format(Date, “m-d-yyyy”)
strDocsPath = GetContactsDocsPath()
Debug.Print “Docs path: “ & strDocsPath
strTemplatePath = GetContactsTemplatesPath()
Check that at least two contacts have been selected, because there is no point of doing a mail
merge to only one contact:
Set lst = Me![lstSelectContacts]
If lst.ItemsSelected.Count < 0 Then
MsgBox “Please select at least one contact”
lst.SetFocus
GoTo ErrorHandlerExit
End If
Clear the merge data table of old data:
DoCmd.SetWarnings False
strTable = “tblMergeData”
strSQL = “DELETE * FROM “ & strTable
DoCmd.RunSQL strSQL
Create a recordset based on the table of merge data:
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(Name:=strTable)
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 NextContact
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 NextContact
End If
Working with Word Documents and Templates 6