When using Word's mail merge feature, you are not limited to using only the actual data fields when putting together your merge document. Word also includes special fields that allow you to conditionally control how Word does the merging. These types of fields can be easily inserted by clicking on the Insert Word Field drop-down list on the Mail Merge toolbar. The three fields you can use for conditional processing are as follows:
You cannot use Word's conditional mail-merge fields to compare values in any record other than the current one. It would be very nice to compare the contents of a data field in the current record with the contents of the same data field in the previous record, but Word will unfortunately not allow it.
One possible workaround to this shortcoming—if you are using an Excel worksheet as your data source—is to simply copy the controlling field (column) to another column, and then offset it by one row. Here is an example:
Item | Category | OldCat | ||
---|---|---|---|---|
Dogs | 1 | |||
Cats | 1 | 1 | ||
Birds | 2 | 1 | ||
Pigs | 3 | 2 |
As Word processes each record of the data source, the value of the OldCat data field is the same as the contents of the Category data field in the previous record. Thus, you could use a compound field such as the following to check and act upon the comparison between the fields:
{IF {MERGEFIELD Category} <> {MERGEFIELD OldCat} "first text" "second text"}
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8176) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365. You can find a version of this tip for the older menu interface of Word here: Conditional Processing During a Mail Merge.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
Word has a great mail merge capability. Inherent in this capability is the option to send your merged documents via ...
Discover MoreUsing the mail merge feature of Word, you can make data from Access databases accessible for your documents. How ...
Discover MoreWhen you merge information with a Word document, you may not be completely satisfied with the appearance of some of the ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2016-12-14 09:23:20
Liz
Is it possible to compare two records. In the data source it will say:
Name Amount
Jane Smith $1,000
Jane Smith $ 500
Jane Smith $6,000
Bob Jones $2,000
Bob Jones $ 750
In may merge I want it to list all of Jane Smith's numbers. When it sees the name has changed I want it to do a new record with Bob's numbers. How would I write that?
2016-07-19 15:57:14
Shelley
I'm not sure how to do this for my data. I need to print address labels and one of my fields is "farm name" which is frequently blank. When blank I want to just skip to the next field. For example for someone with a farm name the label should be:
Name
Farm name
street
city, St zip
while for someone without it would print
Name
street
city, st zip
Thanks!!
2015-02-26 11:33:46
Amara
Hello Allen, I wonder if you can tell me what rule to use and how for my problem at hand. I need to use the mail merge with a data source. I am not using the mail merge for mailing reasons, instead I am trying to print labels for a production plant. Is there a way I can print X amount of copies for 1 record based off of the "quantity" field in the data source? Let's say that my record source has 3 lines/rows. Row1 has a quantity of 2, Row2 has a quantity of 3, and Row3 has a quantity of 1. I will need 2 of the same labels printed for the first row followed by 3 of the same labels for the second row, followed by 1 label for the third row. I look forward to hearing your suggestions!
2014-07-05 22:06:12
Thain Dikkers
Can not get this to work. How do you put the if statement in a Document so it will either print a line or not print the line? Do we need to start with Ctrl F9?
2014-02-02 04:41:01
Jakub
Thank you for resolving! I didn't use Ctrl+F9 for inner brackets in if block.
2014-01-27 15:13:47
awyatt
Jakub,
You need to add the OldCat column in your data source (Excel?) and make sure it is offset by one row from the Category column.
You also need to make sure that your merge fields are put into your Word document as actual fields, using Ctrl+F9 to insert each field (which creates the braces). The fact that you are getting back "Category}" with the ending brace indicates that you're not adding the merge field as an actual field.
-Allen
2014-01-27 15:01:49
Jakub
Hello Allen,
thank you for this tip using If ... Then ... Else in Mail Merge.
But your example doesnt work for me.
In MS Word I have following:
{ MERGEFIELD Item }
{ MERGEFIELD Category }
{ MERGEFIELD OldCat }
{ IF {MERGEFIELD Category} <> {MERGEFIELD OldCat} "first text" "second text" }
And the result for example for second record is:
Cats
1
1
Category}
Instead of:
Cats
1
1
second text
It takes me hours, but I cant figure out why it doesnt work.
Can you help me?
2013-11-11 07:58:01
Bryan
You have poor data structure if changing the order of the records changes the meaning. Also, the point of a mail merge is to separate out each record -- what are you doing with it that you need to compare it to the last one?
(I'm certain I've commented on this topic before, but I can't seem to find it right now).
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2019 Sharon Parq Associates, Inc.
Comments