running a macro during mail merge

I

Imnotabum

Hello,

Would someone please tell me if it is possible to run a macro during a
mail merge? I would like the results of certan merge fields in the new
documents to be based on certain conditions in the datasource. e.g. If
the first record of the datasource has the value of one in the
Customer_Agmt field, then the first merged document should result in
"Customer Agreement" for that corresponding merge field; If there is a
1 in the Trading_Agmt field, then the result should be "Trading
Agreement". Conversely if there is a zero in either of those fields of
the datasource, then the merged document would not list anything. In
some instances, the there can be up to 9 possible entries for one
field. Any help will be appreciated.

I am using Office 2000.
 
P

Peter Jamieson

I am using Office 2000.

You only get to run macros /during/ the merge in Word 2002, which uses
'mailmerge events' to let you do this.

So your options are:
a. use IF fields to substitute pieces of text for the values in your data
source
b. control the merge from a macro, output to a document, and postprocess
the results
c. control the merge from a macro, doing one merge per record in the data
source, and stuff in whatever you want based on the values of the fields in
the mailmerge.datasource.datafields collection.

From what you say, it sounds as if (a) would be enough, e.g.

{ IF { MERGEFIELD Customer_Agmt } = 1 "Customer Agreement" "some other text
of fields or blank" }

etc. You can also nest IF fields (but there is a limit of around 20 to the
levels of nesting permitted).

Is that enough for your requirement?
 
I

Imnotabum

"Is that enough for your requirement?"

Yes, thank you for your kind response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top