Solved

Word Mergefield If-Then-Else Statement

Posted on 2009-05-11
2
992 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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 and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

822 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