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:


Re-hide ZipCode field
With appWord.Selection
.GoTo What:=wdGoToBookmark, Name:=”ZipCode”
.Find.ClearFormatting
.Font.Hidden = True
End With
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

Working with Word Documents and Templates 6

Free download pdf