Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2003 Mail Merge Events 1

Status
Not open for further replies.

JudyL

Instructor
Feb 21, 2001
148
US
I am converting some old (very old) WordPerfect Mail Merge main documents to Word 2003. In the old WordPerfect files there was a mail merge statement that allowed you to nest forms and nest macros. The nesting was triggered by If or Select Case mail merge code so that different files or macros could be run depending on the field value being merged. Some of the nested forms also triggered nested macros. I want to do the same think in Word 2003.

I am thinking that I can do the following but want to be sure I have the concept right. Can someone verify that my thinking is correct.
In the main mail merge document (not sure if this should be a template or not):
1. I would declare an object variable in a class module to respond to the events
2. Write the specific event procedure.
3. Initialize the object.
4. Use the MailmergeBeforeRecordMerge event to check the values and then decide what macros to run.

If this is correct, I have an addtional question.
The nested forms might trigger other macros or nest other forms. How do I keep the process going.
 
Hi Judy,

Depending on what you're trying to do, you may be able to do the lot in Word using field coding, without the need for macros.

Certainly, Word can use a macro to run a mailmerge and execute different statements according to what it finds in the data file, but there may be better ways.

So, perhaps you could give more detail of what it is you're trying to achieve, rather than how you think you need to achieve it.


Cheers
[MS MVP - Word]
 
Thanks for the quick response.
To give you an example, depending on the value of a field, we want to include a file. The file contains a couple of rows of a table that will be placed directly beneath an existing table. The macro would combine the two tables. I know I can use the merge coding to include the text fromt he file. It is the combining of the tables that I need to have happen.

Another example is adding two different watermarks, depending on the value of a field.
 
Hi Judy,

The conditional inclusion of a file is easily handled by an IF field test. For example, you might use something along the lines of:
{IF«DocField»<> "" {INCLUDETEXT {IF TRUE "C:\Users\Judy\Documents\«DocField».doc}"}

For your tables, a number of possibilities exit. You could, for example, have an IF test that outputs one of two versions of the table - one with the extra rows, or one without. Alyernatively, you could allow inter-table paragraph breaks to remain, but format those paragraphs with a 1pt height so as to minimise the apparent break.

If the table row count varies, that suggests you're dealing with a catalog/directory merge (the terminolgy depends on the Word version). If so, you might want to check out my Word 97-2007 Catalogue/Directory Mailmerge Tutorial at:
or

Varying watermarks can likewise be handled via an IF field test.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message. Likwise, you can't type the chevrons (ie '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar.



Cheers
[MS MVP - Word]
 
Thanks.I am familiar with the merge language and have used it quite a bit. This is not a directory or catalog merge. It is a letter of confirmation that has optional text depending on the values in the fields. Your suggestion of having the whole table come in with two versions of it might work in some cases but I am reviewing at least 30 of these documents for a client and am not sure it will work in all cases. I have tried the intertable breaks making the paragraph between only 1pt high but the client does not like that.

In any case, those were just two examples. I really do need to be able to run a macro. I have played with it some more and have a handle on it but want to consider all alternatives. Maintenance of macros would be harder for the client to maintain.
 
Hi Judy,

Given that you believe there is a need to run a macro, the whole process might best be managed by having the macro run the merge process, from start to finish. There is such a macro in my tutorial - for email merges. Word macros can have whatever amount of branching etc you're likely to require. Apart from learning vba (the macro language), it's largely a matter of sorting out the processing logic.

Since you're interested in MailMerge events, you might also want to look at:

Cheers
[MS MVP - Word]
 
Thanks but I think the assembly of the 130 various file combinations that can be brought in based on field values is too complex to have the whole merge process handled completely by macros. I am also familiar with vba but had not used the Mailmerge events before. I think I will use a combination of what you recommended with two versions of the whole table and mergeevents. Thanks for your help.
 
based on field values is too complex to have the whole merge process handled
I'm sure that VBA can handle all your issues ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I know it can but I have to think of the abilities of the client for whom I am doing this. They can handle modifications to the merge language but vba is beyond them. Though I love to get the work, I do need to keep their budget in mind. It's all about ease of maintenance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top