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

x
?
Solved

MS Word Mail Merge with If Then

Posted on 2011-02-23
8
Medium Priority
?
371 Views
Last Modified: 2012-05-11
I can't figure out where my syntax is wrong.....

IF "{MERGEFIELD  CFO_name}" = ''"  "{MERGEFIELD managing_partner}" "{MERGEFIELD CFO_name}"

My result is: CFO_name}

If I use this:
IF "{ MERGEFIELD "CFO_name"}" = ''"  "{ MERGEFIELD "managing_partner"}" "{ MERGEFIELD "CFO_name"}"

my result is: CFO_name


Any help?
0
Comment
Question by:jasgot
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34964643
In the expanded field dispaly that we use, the {} pairs should actually be field delimiters and will appear slightly different on the actual document.

If you get an extra curly bracket after the data from the field CFO_Name in the result document, then it is likely to be that character, and not a field delimiter, because there is no delimiter that maps the start of the field (or at least you haven't shown it).

With that in mind, I suggest that you check the fields again. If you still have a problem, try reducing the document to the failing section and posting it here, so that we can have a look at it.

0
 

Author Comment

by:jasgot
ID: 34964800
The If statement above is what's inside the <ctrl>-<f9> brackets.  I'm not getting the field data followed by the curly, I'm getting "CFO_name}" in the resulting merge.

0
 
LVL 50
ID: 34964837
Hello,

You are using to many quote marks. It should look like this

{IF { MERGEFIELD "CFO_name"} = ''"  "{ MERGEFIELD "managing_partner"}" "{ MERGEFIELD "CFO_name"}" }

No "" quote marks required in the condition (other than for the field name). The syntax is

{ IF condition "do when true" "do when false"}

cheers, teylyn
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 

Author Comment

by:jasgot
ID: 34965057
teylyn;

if I press ctrl-F9 to get the sqiggly braces, then paste in your code without the beginning and ending braces, I get "MERGEFIELD" returned in my document.


0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 2000 total points
ID: 34965184
Hello,

you can't just paste what I've posted. You need to enter each field with the Ctrl-F9 key. And I'm not too sure the "" are required for the mergefield names.

Step by step:

Hit Ctrl-F9
type IF between the brackets and add a space

should look like: {IF }

after the space hit Ctrl-F9 again

should look like: {IF {}}

Between these new brackets, enter
MERGEFIELD CFO_name

Should look like: {IF {MERGEFIELD CFO_name}}

click between the two closing brackets and enter
= ""

Should look like: {IF {MERGEFIELD CFO_name} = ""}

add a space and then two double quotes ""

Should look like: {IF {MERGEFIELD CFO_name} = "" ""}

put the cursor between the double quotes and hit Ctrl-F9

Should look like: {IF {MERGEFIELD CFO_name} = "" "{}"}

between the new pair of {} enter

MERGEFIELD managing_partner

Should look like: {IF {MERGEFIELD CFO_name} = "" "{MERGEFIELD managing_partner}"}

before the last closing bracket enter a space and two quotes ""

Should look like: {IF {MERGEFIELD CFO_name} = "" "{MERGEFIELD managing_partner}" ""}

click between the last two quotes and hit Ctrl-F9

Should look like: {IF {MERGEFIELD CFO_name} = "" "{MERGEFIELD managing_partner}" "{}"}

between the last pair of brackets enter

MERGEFIELD CFO_name

Should look like: {IF {MERGEFIELD CFO_name} = "" "{MERGEFIELD managing_partner}" "{MERGEFIELD CFO_name}"}

That's it.



0
 

Author Closing Comment

by:jasgot
ID: 34965279
Thanks! I appreciate your step by step! :)  My error was that I thought ON:Y the outsie curlies needed to be created by Ctrl-F9, I was using regular curlies for the iside fields :(

Thanks!
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34965955
teylyn,

I gather that you are OK. Are you on the South Island?
0
 
LVL 50
ID: 34966182
G, all fine, thx. I'm in Taranaki, north island
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
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 video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

670 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