Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF merge field in Word 2010 1

Status
Not open for further replies.

kwirky

MIS
Apr 22, 2010
85
AU
Hello,

I am hoping someone can help with the correct syntex for how to do the following.

I have a template with merge fields and I would like to create a new merge field using the IF option.

IF the {offender} is a company (so has PTY LTD or P/L at the end of their name), then this field should be blank. If the {offender} is not a company, then use the {offender} details.

I have started with the following however when I merge the document, I am still seeing results with PTY LTD at the end.

{IF{Offender}={"*PTY LTD"} "" {Offender}}

What am I doing wrong?

Any help would be appreciated.

Thanks
 
The field construct should be:
{IF{MERGEFIELD Offender}= "*PTY LTD" "" {MERGEFIELD Offender}}
or:
{IF«Offender»= "*PTY LTD" "" «Offender»}

Note: The field brace pairs (ie '{ }') for the above examples are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. Likewise, you can't type or copy & paste the chevrons (ie '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar. Further, you must have all of the indicated spaces.

Cheers
Paul Edstein
[MS MVP - Word]
 
Hello,
I have followed your instructions and I am not having any success.

When I use teh following formatting I am still seeing all the results, and this includes those where the offender name contains "Pty".

{IF {<<Offender>>} = "*pty*" "" {Offender}}

What I would like to see is that if any Offender has a Pty at the end of their name, then they are considered a Company and so i want the resultant field to be empty. We only wish to see the details of the individual offenders, not the companies.

Is there a way to do this?

Thank you ,
 
The test is case-sensitive and, since you only specified "*PTY LTD" (note the case), I left it alone. Also, you cannot use two asterisks as you're now trying to do. To eliminate the case issues, you could use:
{IF{MERGEFIELD Offender \* Upper}= "*PTY LTD" "" {MERGEFIELD Offender}}

Cheers
Paul Edstein
[MS MVP - Word]
 
Sorry, one last question.

I have found that there are several possibilities for the entering of company details in the form of Pty Ltd, Pty. Ltd. and P/L

What is the syntax for using an IF OR statement? I think the one I figured out is an AND statement (where all three conditions must be met).

{IF {<<Offender>>}= "*PTY. LTD." IF {<<Offender>>}= "*PTY LTD" IF {<<Offender>>}= "*P/L" "" {<<Offender>>}}

Thanks
 
For that, you could use:
{IF{MERGEFIELD Offender \* Upper}<> "*PTY LTD" {IF{MERGEFIELD Offender \* Upper}<> "*PTY. LTD." {IF{MERGEFIELD Offender \* Upper}<> "*P/L" {MERGEFIELD Offender}}}}
or:
{SET Co {MERGEFIELD Offender \* Upper}}{IF{REF Co}<> "*PTY LTD" {IF{REF Co}<> "*PTY. LTD." {IF{REF Co}<> "*P/L" {MERGEFIELD Offender}}}}

Cheers
Paul Edstein
[MS MVP - Word]
 
Thank you so much. That has worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top