Solved

Word Mergefield If-Then-Else Statement

Posted on 2009-05-11
2
979 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
Comment Utility
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
Comment Utility
This worked!!!! GrahamSkan you are the man!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now