# Mail Merge with duplicate information on several rows



## Maria Cristina (Mar 18, 2016)

Please I need help with the code

I need a mail merge word document to send to each of the different customers.  The letter has different paragraphs depending on the status and office they apply for.  Most of them will give reports and they are also based on the office and status they have, so some of them will need 3 reports when other may need 15 reports.

I have a query that merges all of the information, but I will have rows as they customer has reports were this will be the only information for that customer that is different in the table.
I get the information up to the list of reports, after that I get the information for the next customer. I get the AB, PA, TR, ContactP and Cert. No. for the next record.  I know that it must be on the (" ""}{Set VRID1"{MERGEFIELD VRID}"}{IF {VRID2} <> {VRID1}") but every time I change it then I don't get anything after the reporting dates.

After looking on WD2000:  How to Work Around Duplicate Names in Mail Merge Data I came up with:
Open the Word Document and in Mail merge selected Directory, selected the query from the database and sort it by Customer ID No. and by Report due date.
{ IF {MERGESEQ}="1" "{MERGEFIELD VRID}
{MERGEFIELD LETTERDATE}

{ADDRESSBLOCK}

{MERGEFIELD GREETINGNAME}

{MERGEFIELD DQ1}{MERGEFIELD EU1}{MERGEFIELD DQENREP1}{MERGEFIELD DQEREP1}{MERGEFIELD BNNREP1}{MERGEFIELD BNREP1}
{MERGEFIELD CAMPR}     {MERGEFIELD CAMPF}     {MERGEFIELD CAMPT}     {MERGEFIELD CAMPD}
" ""}{SET VRID1}"{MERGEFIELD VRID}"}{IF {VRID2}<>{VRID1}"
{MERGEFIELD AB}
{MERGEFIELD PA}
{MERGEFIELD TR}
If you have any questions, please do not hesitate to contact {MERGEFIELD CONTACTP}
{MERGEFIELD PERSONSIGNING}
{MERGEFIELD TITLEPERSONSIG}
Certified No:  {MERGEFIELD CERTNOALL}

-----------PAGE BREAK----------------------------------
{MERGEFIELD LETTERDATE}

{ADDRESSBLOCK}

{MERGEFIELD GREETINGNAME}

{MERGEFIELD DQ1}{MERGEFIELD EU1}{MERGEFIELD DQENREP1}{MERGEFIELD DQEREP1}{MERGEFIELD BNNREP1}{MERGEFIELD BNREP1}
{MERGEFIELD CAMPR}     {MERGEFIELD CAMPF}     {MERGEFIELD CAMPT}     {MERGEFIELD CAMPD}
{MERGEFIELD PERIODNAME}     {MERGEFIELD STARTDT}     {MERGEFIELD ENDDT}     {MERGEFIELD RPTDATE}" "
{MERGEFIELD PERIODNAME}     {MERGEFIELD STARTDT}     {MERGEFIELD ENDDT}     {MERGEFIELD RPTDATE}"

Certified No:  {MERGEFIELD CERTNOALL}"}{SET VRID2 "{MERGEFIELD VRID}"}


----------



## Macropod (Mar 18, 2016)

You can use Word's Catalogue/Directory Mailmerge facility for this (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
Microsoft Word Catalogue/Directory Mailmerge Tutorial | Windows Secrets Lounge
or:
http://www.gmayor.com/Zips/Catalogue Mailmerge.zip
The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.

The field coding for this is complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert  your own field names and adjust the formatting to get the results you desire. For some worked examples, see the attachments to the posts at:
mail merge with duplicate names but different dollar amounts
Access to Word, Creating a list from multiple records
Word 2010 Merge from excel into Table Directory | Windows Secrets Lounge

Another option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. An example of this approach can be found at: http://answers.microsoft.com/en-us/...g-tables/8bce1798-fbe8-41f9-a121-1996c14dca5d
The DATABASE field can even be used without recourse to a mailmerge. An example of such usage can be found at: Mail merge into different coloumns

Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
Doug Robbins at http://bit.ly/1hduSCB

In addition to a 'Many to One' merge, the latter handles:
• Merge with Charts
• Duplex Merge
• Merge with FormFields
• Merge with Attachments
• Merge to Individual Documents
• Merge, Print and Staple


----------

