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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MailMerge directory 1

Status
Not open for further replies.

Gokalp

Technical User
Feb 20, 2017
4
US
Hi all,
Looking at the examples displayed on this page, I created a mail merge to generate some quote letters. Overall the letters look good, however I need add a section similar to address part where the content needs to be written once, not repeated like products.
To be more clear, there are three sections in my letter:
A- Company info and contact details- Printed once on each letter
B- Products info- Repeats as many times as there are products, so probably a loop.
C- Closing info- Closing note for each letter.

The problem I am having is with the closing info, since right after the products, I am checking if the customer is same or not, I am having hard time to place the correct data into the closing info section.
Below is the code that I am using:

{QUOTE {IF{MERGESEQ}= 1 "{SET Key ""}{SET Person ""}" "{SET LastPerson {Person}}"}{IF{QUOTE{MERGEFIELD
Customer_Name}}<> {Key} "{ MERGEFIELD InternalText1 } {IF{MERGESEQ}> 1 "{SET LastPerson {Person}}
[highlight #FCE94F]We look forward to your next order.
{ MERGEFIELD InternalText1 }
Sincerely,
_________________________________
John Doe[/highlight]
{IF{MERGEFIELD Customer_Name}<> 0 "
-------------page break--------------------

"}"}{IF{MERGEFIELD Customer_Name}<> 0 "{SET Key {QUOTE{MERGEFIELD Customer_Name}}}{SET Person
{QUOTE{MERGEFIELD Customer_Name}}}
{MERGEFIELD Customer_Name }
{MERGEFIELD Contact } {DATE \@ "MMMM d, yyyy"}
{MERGEFIELD Address1 }
{MERGEFIELD City }{MERGEFIELD State \b " "}{MERGEFIELD Zip \b ","}
Dear {MERGEFIELD Name}
Thank you for your business. The following are updated prices:
Product Units Price QC Code Your Code
"}"}"{IF{MERGEFIELD Customer_Name}<> 0 "{MERGEFIELD Product_Name} {MERGEFIELD Size}
{MERGEFIELD Unit} {MERGEFIELD Form} {MERGEFIELD
Final_Price\# $#,##0.0000 } {MERGEFIELD ProductID} {MERGEFIELD Customer_Text}
"}"}

The highlighted section will pick up the info from the next company, not the current one. What's the correct placement of this mergefield, so that it shows the right info at the right spot.

Thank you in advance,
G
 
Your field code appears to be based on my Microsoft Word Catalogue/Directory Mailmerge Tutorial, available at:
or:

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. Notwithstanding your reservations, the post-group coding does occur before the code for the opening content and grouped data. For some worked examples, see the attachments to the posts at:

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:
You should also note that previews of such a complex merge are unlikely to show the correct results; you need to actually Finish the merge.

Cheers
Paul Edstein
[MS MVP - Word]
 
Paul, thank you so much for your assistance, yes I used one of your examples to create this, WSM one. I will take a look at the examples one more time and see what I am doing wrong.
 
Paul, I am hoping you can provide some assistance with the WSM example. In the source document- excel sheet- there is a notes section. Let's say I want that to be printed, adding {MERGEFIELD Notes} does not show the note in the correct account/customer.
Thank you

 
You can do that using the same approach the WSM document takes for the replication of the recipient's name/organisation in the latter part of the letter, via the {SET Person ""}, {SET LastPerson {Person}}, {LastPerson} and {SET Person {QUOTE{{MERGEFIELD FirstOrganization}}} fields. Simply follow each of those SET fields with one corresponding to the Notes field in the data source. For example, you might add:
{SET Note ""};
{SET LastNote {Note}}; and
{SET Note {QUOTE{{MERGEFIELD Notes}}}}
so that you end up with:
{SET Person ""}{SET Note ""};
{SET LastPerson {Person}}{SET LastNote {Note}}; and
{SET Person {QUOTE{{MERGEFIELD FirstOrganization}}}){SET Note {QUOTE{{MERGEFIELD Notes}}}}
You would then insert the {LastNote} field wherever you need it to appear, perhaps with some logic to add line-feed only if it's not empty , for example:
{IF{LastNote}<> "" "{LastNote}↵
"}

Cheers
Paul Edstein
[MS MVP - Word]
 
Thank you Paul, that worked, the letters are coming out just how I expected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top