Access.2007.VBA.Bibl..

(John Hannent) #1

Create a new save name with the incremented number:


intSaveNameFail = True
strSaveName = strDocType & “ “ & CStr(i) _
& “ to “ & strContactName & “ - “ _
& strCompanyName
strSaveName = strSaveName & “ on “ _
& strShortDate & strExtension
strSaveNamePath = strDocsPath & strSaveName
Debug.Print “New save name and path: “ _
& vbCrLf & strSaveNamePath
i = i + 1
Else
Debug.Print “Save name not used: “ & strSaveName
intSaveNameFail = False
End If
NextContact:
Loop

Update fields in Word document and save it:


With appWord
.Selection.WholeStory
.Selection.Fields.Update
.Selection.HomeKey unit:=wdStory
.ActiveDocument.SaveAs strSaveNamePath
End With

Next varItem

With appWord
.ActiveWindow.WindowState = wdWindowStateNormal
.Visible = True
.Activate
End With

ErrorHandlerExit:
Exit Sub

ErrorHandler:
If Err = 429 Then
‘Word is not running; open Word with CreateObject
Set appWord = CreateObject(Class:=”Word.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If

End Sub

Working with Word Documents and Templates 6

Free download pdf