Access.2007.VBA.Bibl..

(John Hannent) #1
Write information to Word bookmarks in the document:

With appWord.Selection
.Goto what:=wdGoToBookmark, Name:=”LetterDate”
.TypeText Text:=Format(Date, “Long Date”)

.Goto what:=wdGoToBookmark, Name:=”RecipientName”
.TypeText Text:=strRecipientName

.Goto what:=wdGoToBookmark, Name:=”RecipientAddress”
.TypeText Text:=strRecipientAddress

.Goto what:=wdGoToBookmark, Name:=”RecipientZip”
.TypeText Text:=strRecipientZip

.Goto what:=wdGoToBookmark, Name:=”Salutation”
.TypeText Text:=strSalutation

.Goto what:=wdGoToBookmark, Name:=”EnvelopeName”
.TypeText Text:=strRecipientName

.Goto what:=wdGoToBookmark, Name:=”EnvelopeAddress”
.TypeText Text:=strRecipientAddress

.Goto what:=wdGoToBookmark, Name:=”EnvelopeZip”
.TypeText Text:=strRecipientZip

Reinsert the EnvelopeZip bookmark so the zip code will be available for use by the bar code field
on the envelope:

.MoveLeft Unit:=wdWord, Count:=3, Extend:=wdExtend
doc.Bookmarks.Add Range:=Selection.Range, _
Name:=”EnvelopeZip”

.Goto what:=wdGoToBookmark, Name:=”LetterText”
strPrompt = “Ready to enter letter text”
strTitle = “Access data imported”
MsgBox strPrompt, vbOKOnly, strTitle
appWord.Visible = True
appWord.Activate

End With

ErrorHandlerExit:
Set appWord = Nothing
Exit Sub

ErrorHandler:
If Err = 429 Then

Part I The Office Components and What They Do Best

Free download pdf