You are here:

Microsoft Word/Legacy Form Fields - IF Statements

Advertisement


Question
QUESTION: I have a sales form which includes a dropdown list of three options for the question, "Shipping Options". The optional responses are; A)Yes-Within US, B)Yes-Outside US and C)Pick Up in Store. I have an additional calculated field for the actual shipping charges which I want to base on this field; If option A, then shipping charges is total of product cost X 1%; If option B, then shipping charges is total of product cost X 5% and finally if Option C, then I want it to display the text "No charge" (A zero will suffice, but I would really like to know if you can mix in Text values.) Can I write an IF Statement to accomplish this and if so, how would it be formatted. I keep getting syntax errors. Thank you.

ANSWER: The bottom-line answer to this question is that yes, you absolutely can do this. However, instead of trying to do it with a single IF field (which would require nesting, which becomes complex), it is much simpler to do it with three IF fields. Since you have three simple conditions for which you have a TrueText (no FalseText needed because the choices are mutually exclusive), this is the easiest way to do it.

The first thing you need to know is the bookmark of the dropdown list field. By default, it will be "Dropdownx," where x represents a number. If it's the first dropdown field on the form, it will be Dropdown1. In the Form Field Options dialog, you can assign a more meaningful bookmark; for the purposes of this illustration, let's say that the bookmark is ShippingOptions. For our purposes, we will also assume that the calculated field that reports the total is called Total. Both of these fields are set to "Calculate on exit."

The three IF fields you will need will have the following syntax. Note that, while I'm showing them on three separate lines, you will want to put them all in a single paragraph so that you don't have empty paragraphs representing the two fields whose conditions aren't met. I can't emphasize enough that the text of the dropdown field options must *exactly* match the text in the IF fields; I struggled getting the "Outside US" field to work because (apparently) the text in the dropdown ended in a space (I had copy-pasted the text exactly from your question but had evidently inadvertently picked up a trailing space). I've used the text you gave minus the ABC; you'll need to modify the fields as required to adjust for the exact text used, bookmark names, etc.

{ IF { REF Shipping Options } = "Yes-Within US" "{ = .01 * Total }" }
{ IF { REF Shipping Options } = "Yes-Outside US" "{ = .05 * Total }" }
{ IF { REF Shipping Options } = "Pick Up in Store" "No Charge" }

Each pair of field braces { } must be inserted using Ctrl+F9.

---------- FOLLOW-UP ----------

QUESTION: Thank you for answering so quickly!! I'm still having trouble, however. Not certain what I'm doing wrong? I need some clarification on three things. 1) Help me understand why I need the "REF" in front of the bookmark name? (I assume the space between the words "Shipping" and "Option" was a typo?) 2) When I combine these three lines into a "paragraph", do I need spaces or a comma between the brackets? 3) I'm not understanding how to correctly use the Ctrl+F9 function. Why can't I simply add them manually? If there's a way I can send you my form, I would love to, but I don't see an option for that. (Note: The field in the formula should be "SubTotal". Then there's another field called GrandTotal of the customer order.)

Answer
1. For some reason bookmarks in an IF field have to be inserted as REF fields. Evidently the same is not true of formula (=) fields; I did start out with REF fields there, too, but discovered I didn't need them. And yes, it should be "ShippingOptions." Sorry!

2. When you combine the lines, you should have no space or punctuation between them (the fields will wrap and be a little harder to parse, which is why I suggest creating them separately at first). Keep in mind that your result will include not only the field result but also any plain text you include, and all you want is the calculated shipping charge. So what you should end up with is:

{ IF { REF ShippingOptions } = "Yes-Within US" "{ = .01 * Total }" }{ IF { REF ShippingOptions } = "Yes-Outside US" "{ = .05 * Total }" }{ IF { REF ShippingOptions } = "Pick Up in Store" "No Charge" }

If you're doing this in a table, you may want to create the fields outside the table and then cut and paste them in. It can be very frustrating trying to view complex fields within a table cell.

3. When you press Ctrl+F9, you get a blank field: the field delimiters (which look like braces but can't by entered from the keyboard) and two spaces, with the insertion point placed between them. You type the text of your field in that space. Whenever you have another field (such as the REF field) inside your IF field, you use Ctrl+F9 to insert another blank field. You can use Insert | Text | Quick Parts | Field to insert an IF field, but you're still going to have to edit it by hand to insert the REF field. The Field dialog is absolutely no help for the IF field, anyway, as there are no "Options" that you can click to insert expressions or switches, so you basically have to create it by hand whether you do it in the dialog or in the document. You will, of course, have to modify the syntax to reflect the bookmarks you have used; the ones I used were just examples for demonstration purposes.

The important thing to know when dealing with fields is that you view the field code by pressing Alt+F9. You can then toggle to the field result by pressing Alt+F9 again, but if you have made any changes in the field syntax, you may also need to press F9 to update the result. Also, be aware that you'll get a syntax error if the Total field is empty. I made this mistake when I printed out the field codes to copy into my answer yesterday. I had forgotten that printing would update the fields, which had the effect of clearing the form field I was using for the total, with the result that the first two IF fields were trying to multiply by 0!
About Microsoft Word
This topic answers questions related to Microsoft Word stand-alone or Microsoft Office Word including Word 2003, Word 2007, Office 2000, and Office XP. You can get Word help on formatting text, tables, tabs, fonts, styles, general Word layouts, bullets, headings, and outlines, using templates, toolbar modifications, and using Track Changes. You may also find tips on linking Word and Excel embedded objects including charts. This site does not provide a general Word tutorial nor the basics of using a word processor. It provides specific answers to using Microsoft Word only. If you do not see your Word question answered in this area then please ask a Word question here

Microsoft Word

All Answers


Answers by Expert:


Ask Experts

Volunteer


Suzanne S. Barnhill

Expertise

I've been using Word for Windows since version 2.0 (1992), and the more I learn about it, the more I realize how little I know. But I may know a few things that you don't, and I'll help if I can. I answer many questions every day in Microsoft's peer support forums and as a result have been awarded the MVP (Most Valuable Professional) designation by Microsoft Corporation. You may be able to find the answer to your question at the Word MVPs' FAQ site or at my own Word FAQ site, so please check those first! Please, no questions about VBA (macros), Registry editing, networks, or complex merges, as I have no experience with these aspects of Word, nor do I have any experience with Word for Mac. Please indicate which version of Word you are using; if you are not sure, see "What version of Word do I have?".

Experience

I have a master's degree in classics (Latin), which is surprisingly helpful, though I no longer teach. The things I am proudest of: Having raised two children to maturity, both Merit Scholars, both college graduates (one a philosophy major!), one Phi Beta Kappa (from Harvard!); having been made a Paul Harris Fellow by my Rotary club; having been designated a Microsoft MVP.

Organizations
Rotary Club of Fairhope, Friends of the Fairhope Public Library

Education/Credentials
B.A. (Latin), Agnes Scott College, 1966; M.A. (Classics), Emory University, 1972.

Awards and Honors
Microsoft Most Valuable Professional award every year since 1999; many Rotary honors

©2016 About.com. All rights reserved.