Link to home
Start Free TrialLog in
Avatar of mlagrange
mlagrangeFlag for United States of America

asked on

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

Avatar of irudyk
irudyk
Flag of Canada image

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

Avatar of mlagrange

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of irudyk
irudyk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!