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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word 'If' and Merge Fields 1

Status
Not open for further replies.

benjamenus

Programmer
Dec 3, 2001
157
0
0
GB
Hi

I have three merge fields (Title, FirstName, Surname) which I want to appear in my letter e.g.

Dear <<Title>> <<FirstName>> <<Surname>>

However, sometimes the Title is blank. On these occassions I'd like the whole name string (i.e. all three fields) to be replaced with "Sir/Madam".

The format seems to be:

Dear {If {Title MERGEFIELD}="" "Sir/Madam" {Title MERGEFIELD}}

Basically, if Title is blank insert "Sir/Madam" else insert Title.

However, what I want it to do on the 'else' is insert the Title, FirstName and Surname. But when I put all three in the 'If' statement, only the first comes out - seemingly because a space is used to separate the items as well as the conditions.

Is there a way of grouping the three merge fields?

Cheers

P.S. I've already achieved what I'm after by using three 'If' statements, but I'm sure there must be an easier way of achieving this along the lines described above.
 

Hi,

Did you check Word HELP?

HELP said:
{ IF { MERGEFIELD Company } <> " " "{ MERGEFIELD CompanyAddress }" "{ MERGEFIELD HomeAddress }" }

Skip,
[sub]
[glasses] [red]Sign above the facsimile apparatus at the music publisher:[/red]
If it ain't baroque...
Don't FAX it![tongue][/sub]
 
Hi Skip

I'm not sure I understand the solution or if it achieves what I'm after. It looks to be saying:

if company is not blank insert company address otherwise insert the home adress

What I want to do is more along the lines of:

if company is not blank insert company address otherwise insert (the home adress AND the home telephone)

i.e. insert two (or more) separate fields if the condition is met. What I need is a way of grouping these fields. I've tried " but it then treats the fields at text. () don't work either
 


Please post what you have tried and does not work.

Skip,
[sub]
[glasses] [red]Sign above the facsimile apparatus at the music publisher:[/red]
If it ain't baroque...
Don't FAX it![tongue][/sub]
 
Hi Skip

This achieves what I was after

{IF {MERGEFIELD ContactTitle}="" "Sir/Madam" {MERGEFIELD "ContactTitle"}} {IF {MERGEFIELD ContactTitle}<>"" {MERGEFIELD "ContactFirstName"} ""} {IF {MERGEFIELD ContactTitle}<>"" {MERGEFIELD "ContactLastName"} ""}

However, I was hoping that I could achieve the same thing with a single IF statement. Unfortunately, only the first field under the ELSE comes out though.

{IF {MERGEFIELD ContactTitle}="" "Sir/Madam" {MERGEFIELD "ContactTitle"} {MERGEFIELD "ContactFirstName"} {MERGEFIELD "ContactLastName"}}
 
Hi benjamenus,

This should do what you want ..

{IF {MERGEFIELD ContactTitle}="" "Sir/Madam" [highlight]"[/highlight]{MERGEFIELD "ContactTitle"} {MERGEFIELD "ContactFirstName"} {MERGEFIELD "ContactLastName"}[highlight]"[/highlight]}

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony

Thanks for the suggestion, but when I use " it treats it all as text. I've also tried brackets () but it still only uses the first one!
 
Hi benjamenus,

Tony's field coding is correct, though you could simplify it still further:
{IF{MERGEFIELD ContactTitle}="" "Sir/Madam" "{MERGEFIELD ContactTitle} {MERGEFIELD ContactFirstName} {MERGEFIELD ContactLastName}"}

Cheers
 
Hi benjamenus,

I'm not sure what you mean when you say it treats it all as text - you are entering all the braces via Ctrl+F9, aren't you? If so, can you be a bit more specific about what you get?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks for your help everyone (pink star for tony). Sorry it's taken so long to get back to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top