Solved

Word Mergefield If-Then-Else Statement

Posted on 2009-05-11
2
999 Views
Last Modified: 2012-05-06
I am trying to conditionally display the spouse2 address if it is different then spouse1 address.  Both spouses are included in the same data record.

For instance, lets say:

Spouse1:  John Smith
Add1       12 Tent Rd
Add2
Add3
City          Atlantic City
State        NJ
ZipCode  075265

Spouse2:  Loretta Smith
Add1        68 Wake Dr
Add2        Suite 3625
Add3
State        Trenton
State        NJ
ZipCode   075155

I am trying to develop a conditional statement based on Add1.  If the same, then blank else print each address.  So if the address it the same I could do the following:

John and Loretta Smith
12 Tent Rd
Atlantic City, NJ 075265

If different address lines, then it should display Spouse1 and Spouse2 with separate name and addresses.  
 
If Spouse1.Add1 = Spouse2.Add1 then ""
Else
Spouse1.Name
Spouse1.Add1 chr(130 +
Spouse1.Add2 chr(13) +
Spouse1.Add3 chr(13) +
Spouse1.City, Spouse1.State, Spouse1.ZipCode 
chr(13)
chr(13)
Spouse2.Name
Spouse2.Add1 chr(130 +
Spouse2.Add2 chr(13) +
Spouse2.Add3 chr(13) +
Spouse2.City, Spouse2.State, Spouse2.ZipCode

Open in new window

0
Comment
Question by:cmp119
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 24357171
You will need to display the field codes instead of the field results. You can toggle between the two views with Alt+F9. Merge fields will then look like:
{ MERGEFIELD MyField } instead of <<MyField>>.

You then need to nest your merge fields, paragraphs and any other text inside an IF field. Note that the {} field pairs must be entered either with Ctrl+F9 or will appear when a field is is entered on the document.

The paragraph marks are shown here. You can toggle their visibiklity with the ¶ button. Also I may be wrong, but I don't think that a dot (full stop) is allowed in a field name, so I have omitted them.

{IF { MERGEFIELD Spouse1Add1 } <> { MERGEFIELD Spouse2Add1 } "{ MERGEFIELD Spouse1Name }¶
{ MERGEFIELD Spouse1Add1 }¶
{ MERGEFIELD Spouse1Add2 }¶
{ MERGEFIELD Spouse1Add3 }¶
{ MERGEFIELD Spouse1City }, { MERGEFIELD Spouse1State }, { MERGEFIELD Spouse1ZipCode }¶


{ MERGEFIELD Spouse2Name }¶
{ MERGEFIELD Spouse2Add1 }¶
{ MERGEFIELD Spouse2Add2 }¶
{ MERGEFIELD Spouse2Add3 }¶
{ MERGEFIELD Spouse2City }, { MERGEFIELD Spouse2State }, { MERGEFIELD Spouse2ZipCode }"¶
 }¶


0
 

Author Closing Comment

by:cmp119
ID: 31580144
This worked!!!! GrahamSkan you are the man!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question