Microsoft Word 2010 If-Then Statements

Hello:

I have a Word 2010 document that contains a field that contains a checkbook ID.

I want to create an "if, then" statement that says if checkbook ID = "A", then display "this logo"; if checkbook ID = "B", then display "that logo".

I'm appalled that I cannot find any documents on the internet that address how to create if, then statements in Word.

Can someone please tell me how to create if, then statements in Word?  I'm at a loss!

Thanks!

Much appreciated!

TBSupport
LVL 1
TBSupportAsked:
Who is Participating?
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.

EirmanChief Operations ManagerCommented:
0
DrTribosCommented:
Are you wishing to do this with VBA or with fields?  

With fields you could start like this:

{ IF "A" = "A" { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicTrue.png } { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicFalse.png }}

Where the {} are fields entered using insert quickparts > fields   OR   press Ctrl + F9
A = A is a dummy config that = true
A = B used to test false...

I'm not sure if you can get a field to look at a checkbox value...
0
DrTribosCommented:
So you can get your checkbox to change a doc variable called cb1 using VBA like this:

activedocument.Variables("cb1").Value = "True"
activedocument.Fields.Update

And then the fields in the document can do the rest, like this:
{ IF {DOCVARIABLE cb1 } = "True" { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicTrue.png } { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicFalse.png }}

(note the double slashes are required)

HTH
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

DrTribosCommented:
Gah! I read checkbook as check box!  Talk about a red herring!

{ set cbook "Checkbook A" }    <-- This is your field with assigned text

It is not clear from your post how you want to interact with this document.  Assuming you want to use fields, and there are only 2 checkbooks you could use a simple IF.  

If you want to change to check book B you'd have to change this field { set cbook "Checkbook A" } to { set cbook "Checkbook B" }   (A to B).

{ IF { cbook } = "Checkbook A" { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicTrue.png } { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicFalse.png }}

then you can do like this:
Payment made by { cbook }, thank you.

Which would display:
Payment made by Checkbook A, thank you.

If there are more than 2 Checkbooks then you would find yourself using nested IF - the basic logic is {IF ?=? DisplayTrue {IF ?=?? DisplayTrue {IF ?=??? DisplayTrue DisplayFalse}}}  <--This would give you 4 Check books to choose from.

If you want to get more tricky, I think you'd have to go to VBA.
0
DrTribosCommented:
If you want to get more tricky, I think you'd have to go to VBA.

I was wrong... fields can let you be more tricky :-)

You can make your IF field display almost anything.  Say you have the text in your document:

I want to use checkbook ?

Put a bookmark around [checkbook ?] by selecting it and pressing ALT > i > k (or go througt the ribbon) then give the bookmark a name:  cbook

Then we make a reference field to the bookmark, this field will display the bookmark text anywhere in the document.  Example you insert { REF cbook } in the middle of your text and it will resolve to whatever text is in the bookmark.

Now... to get what (I think you want) the field codes would look like:
{ IF { REF cbook } = "checkbook A" { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicTrue.png } { INCLUDEPICTURE  "C:\\MyPicPath\\MyPicFalse.png }}

With this approach you can simply type over the '?' and make it an 'A' or 'B'... you will have to update the fields each time you change the text contained by the bookmark.  A quick way to update all fields is by using print preview.

HTH
0
TBSupportAuthor Commented:
Thanks, Dr. Tribos!  This is good information, and your most recent posting is especially helpful.

I could not get this to work, because I don't understand the syntax for the Insert Fields.  Here's what I have:

IF REF ACBRTCDISC  = "ACBRTCDISC" IncludePicture L:\\GP Templates\RTC Logo_090513PM.png IncludePicture L:\\GP Templates\\PCI Logo_090513PM.png   \* MERGEFORMAT  \* MERGEFORMAT

Can you please let me know where to put the brackets in, etc.?

I've attached the Word template.  In the tope right hand-corner, I have the if-then field called "ACBRTCDISC".  This is the name of the checkbook ID, as well.

Speaking of which, just below that field is the bookmark "ACBRTCDISC".

Thanks!  

TBSupport
Check-Remittance-Template-LogoCh.docx
0
DrTribosCommented:
Hi TBSupport,

I added a missing "\" in the first INCLUDEPICTURE.  To add the curly brackets you can select the text and press Alt + F9, this will apply field codes.  Each field is marked with these codes and there are fields within fields (nested).  In total there are 4 fields, 1 outer and 3 inner.  

I have updated your document, if the fields or text are NQR you can edit.

Cheers
Check-Remittance-Template-LogoCh.docx
0
TBSupportAuthor Commented:
Hi Dr. Tribos:

Unfortunately, the app that I work with could not generate your file.

I took your thoughts in the last posting and fixed my syntax.  But, I'm still not able to get this to work.

In taking a look at your file, where in the world is the If-Then statement field?  I tried moving the logo to see if it was behind it.  But, no dice.

Do I have to have a "picture" field already on the document?  Is there not just a way to place the If-Then field in a square or something and have it pull the applicable logo from Windows Explorer?  I've been trying this all day without success.

I don't think that I've ever been this frustrated in my life.  I can't believe Word doesn't offer conditional formatting or whatever like Excel does.

TBSupport
0
DrTribosCommented:
Hi,

The field codes are hidden by default... you can view them by first selecting them & then pressing Shift+F9.

Your field codes are in the document header.  Double click the header to edit it, then press Ctrl+A (select all)  then press Shift+F9 (toggle field codes).
Screenshot showing If fields in word documentTo update the fields you need to select the field and then press F9, or (assuming Update Fields before printing option is set) go into print preview and all fields should update.

Hope this helps.
0

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
DrTribosCommented:
Thank you :-)
0
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.