Word 2010 - vba - Mail Merge .. can I condition a database field with IF?

Hi EE,

How can I condition these fields to print only if NOT NULL. (the fields have data)

it's hard for me to paste the mail merge logic into this window, bec it pastes the actual student data.

So below is a screen shot.

Especially want to have the word "Grade:" appear before the field-grade, only if the grade is present.

You see this word doc has up to 15 courses, not necessarily all filled in.

Up until now I got away with not having to code an IF, bec if the fields were blank it just showed blank.

But now that have to add the Grade field to report, it's nicer to precede the field with the Grade literal.

thx for your help, sandra

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You would need to use something like this:

{ IF {MERGEFIELD Grade}  = "" "" "Grade  { MERGEFIELD Grade }" }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mytfeinAuthor Commented:
Hi Graham,

thx so much for replying...

will go try it and get back to you soon...

tx, sandra
mytfeinAuthor Commented:
Hi Graham,

Sorry for the delay:

I tried this, and it is printing in the document as the entire IF logic as the literal below , not as the field value

{ IF {MERGEFIELD Clerkship_Grade_1}  = "" "" "Grade:  { MERGEFIELD Clerkship_Grade_1 }" }

Also, can you pls explain/break down the "s  (double quotation marks)

tx, sandra
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Firstly, please understand that I have posted only what it looks like. The { and } symbols are intended to represent field delimiters, and can not be typed in using the corresponding keys. They must be entered, either as an empty pair with Ctrl+F9 or as a part of inserting a field via Insert tab, Quick parts, Field... item.

In order to edit field contents, please use Alt+F9 to toggle the display between showing the code and showing the field result.

The logic is (in pseudo VBA format:

IF {MERGEFIELD Clerkship_Grade_1}  = "" then
    output ""' (nothing)
    output "Grade:  { MERGEFIELD Clerkship_Grade_1 }"
end if

I have created  a source field that includes a field named "Clerkship Grade 1" and it seems to work OK
mytfeinAuthor Commented:
Hi Graham,
thx so much for explaining...

If you still have your test word doc, if you have time, can you please upload it...

Maybe I can cut and paste your logic.... or would that not work bec of the above explanation...?

tx, sandra
I'm not sure that I saved the document or the datasource, but will upload them if I did. It should be possible to copy and paste the field complex between documents.
If I can't find it, I'll do it again as soon as I can.
mytfeinAuthor Commented:
Hi Graham,

thx so much for your help,

so both ideas based on your guidance work:

Below is a screen shot, could not paste the text in this window....

My user decided she does not need the literal: Grade

So first idea is using actual field
Second idea is using a literal of "XXXX"

In both ideas, if field is "", putting instead a space like this " "

tx again, G-d bless you and yours, sandra

screen shot
tx, sandra
Sorry. I went to bed immediately after my last post and have only just got back to the keyboard, so hadn't got around to recreating the sample datasource and merge document before you worked it out for yourself and posted your final comments.

Well done. I often give minimal answers in the hope that askers will do what you have done and so learn in the process.
mytfeinAuthor Commented:
mytfeinAuthor Commented:
Hi Graham,

Just clicked on the 3 articles that you wrote and found something fascinating and relevant to my comments above about not being able to past Word logic into this web site:


will read it further!

thx sooooo much,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.