The code that creates the document with text written to doc properties is listed as follows:
Private Sub cmdDocProps_Click()
On Error GoTo ErrorHandler
Dim appWord As Word.Application
Dim doc As Word.Document
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strTemplatePath As String
Dim strTemplateName As String
Dim strTemplateNameAndPath As String
Dim lngContactID As Long
Dim strRecipientName As String
Dim strRecipientAddress As String
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
Dim prps As Object
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 Templates path from the Word Options dialog:
strTemplatePath = _
appWord.Options.DefaultFilePath(wdUserTemplatesPath) _
& “\”
Debug.Print “Templates folder: “ & strTemplatePath
strTemplateName = “Milano Letter (Doc Props).dotx”
strTemplateNameAndPath = strTemplatePath & strTemplateName
On Error Resume Next
Creating Word Documents from Access 2