Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Word Mergefield If-Then-Else Statement

Posted on 2009-05-11
2
Medium Priority
?
1,021 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

688 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