How to update mail merge FIELDS and links?

Hello - This is an Access/Word 2003 app, with some pretty involved mail merge operations.

The mail merge doc's have a lot of IF fields that set different text into the letters, based on data values in the datasource (different account types from record to record).

They also have INCLUDEPICTURE fields to bring in the signature jpg's of the various cust service rep's, based on their user ID's I plant in the datasource (also varies from record to record).

After I "Mail Merge To A New Document", I have to press Control/A to select the entire thing (hundreds of letters, on average), and then press F9 to update the fields and links. I'd like to do that in code, but I don't see any likely-looking methods of the Document object to do that.

How do you, in VBA, from the Access side, do a Control/A followed by F9? (code snip below)

(I just thought about doing it with SendKeys, but there has to be an object method?)

Thanks




Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim objWordMrg As Word.Document
 
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = True
 
Set objWordDoc = objWordApp.Documents.Open("C:\MyMailMergeLetter.doc")
 
objWordDoc.MailMerge.OpenDataSource _
	Name:=GetCurrentDBNamePath_TSB(), _
	LinkToSource:=True, _
	SQLStatement:="SELECT * FROM [tblMyMailMergeDataSource]"
 
objWordDoc.MailMerge.Execute
 
Set objWordMrg = objWordApp.ActiveDocument
 
objWordDoc.Close

Open in new window

mlagrangeAsked:
Who is Participating?
 
irudykConnect With a Mentor Commented:
Sorry for not getting back to you on this sooner...I hear what you are saying.  Well, maybe the following will work since it selects the contents of the document first before attempting to update the fields

Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim objWordMrg As Word.Document
 
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = True
 
Set objWordDoc = objWordApp.Documents.Open("C:\MyMailMergeLetter.doc")
 
objWordDoc.MailMerge.OpenDataSource _
	Name:=GetCurrentDBNamePath_TSB(), _
	LinkToSource:=True, _
	SQLStatement:="SELECT * FROM [tblMyMailMergeDataSource]"
 
objWordDoc.MailMerge.Execute
 
Set objWordMrg = objWordApp.ActiveDocument
objWordMrg.ActiveWindow.Selection.WholeStory
objWordMrg.ActiveWindow.Selection.Range.Fields.Update
 
objWordDoc.Close

Open in new window

0
 
irudykCommented:
Try adding:
objWordMrg.Fields.Update

Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim objWordMrg As Word.Document
 
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = True
 
Set objWordDoc = objWordApp.Documents.Open("C:\MyMailMergeLetter.doc")
 
objWordDoc.MailMerge.OpenDataSource _
	Name:=GetCurrentDBNamePath_TSB(), _
	LinkToSource:=True, _
	SQLStatement:="SELECT * FROM [tblMyMailMergeDataSource]"
 
objWordDoc.MailMerge.Execute
 
Set objWordMrg = objWordApp.ActiveDocument
objWordMrg.Fields.Update
 
objWordDoc.Close

Open in new window

0
 
mlagrangeAuthor Commented:
I apologize for letting this sit so long.

I tried .Fields.Update; it does not bring in the signature jpg's

Is this possibly a 2-step thing? the path in the INCLUDEPICTURE actually contains a merge field, istelf:
{INCLUDEPICTURE "T://AppFolder//SigsFolder//{ MERGEFIELD "CustSvcRepID" }.jpg" \d }

I probably should have mentioned that in the original post; sorry again...
0
 
mlagrangeAuthor Commented:
Ok, that got me in the ballpark; this is what finally did it:

    Dim rng As Range
    For Each rng In objWordMrg.StoryRanges
        rng.Fields.Update
    Next

Thanks very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.