Dim strRecipientZip As String
Dim strPrompt As String
Dim strTitle As String
Dim strSalutation As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
lngContactID = Nz(Me![ContactID])
If lngContactID = 0 Then
strPrompt = “No contact selected”
strTitle = “Problem”
MsgBox strPrompt, vbOKOnly + vbExclamation, strTitle
GoTo ErrorHandlerExit
Else
strRecipientName = Nz(Me![FirstNameFirst])
strRecipientAddress = Nz(Me![RecipientAddress])
strSalutation = Nz(Me![FirstName])
strRecipientZip = Nz(Me![PostalCode])
End If
Set appWord = GetObject(, “Word.Application”)
Get the default User Template path from the Word Options dialog (it is still available in code,
though it has disappeared from the Word 2007 interface):
strTemplatePath = _
appWord.Options.DefaultFilePath(wdUserTemplatesPath) _
& “\”
Debug.Print “Templates folder: “ & strTemplatePath
strTemplateName = “Milano Letter (Bookmarks).dotx”
strTemplateNameAndPath = strTemplatePath & strTemplateName
On Error Resume Next
Try to locate the template in the default Templates folder, and put up a message if it is not found:
Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = “Can’t find “ & strTemplateName _
& “ in “ & strTemplatePath & “; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If
On Error GoTo ErrorHandler
Set doc = appWord.Documents.Add(strTemplateNameAndPath)
Creating Word Documents from Access 2