Share via

Quick parts "IF" conditional statement help.

Anonymous
2010-08-03T12:49:00+00:00

I'm trying to to modify document content based on DOCPROPERTY's such as Title, but the IF conditional statement is not behaving as I would expect.  For example: { IF { DOCPROPERTY Title } = "xyz" "True" "False" } returns the text "DOCPROPERTY" instead of "True" or "False".  I think I have a syntax error.  I've tried numerous variations, but can't seem to get it to work.  Can someone please help?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2010-08-03T13:36:54+00:00

In a nested field like { IF { DOCPROPERTY Title } = "xyz" "True" "False" } you must use Ctrl+F9 to create both sets of field braces; you can't simply type the { } characters.

Display the field code. Select the text

   DOCPROPERTY Title

and press Ctrl+F9. Delete the typed brace characters. Update the field, and it should work as expected.


Jay Freedman

MS Word MVP  FAQ: http://word.mvps.org

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

12 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-04-07T11:31:48+00:00

    At least

    1. Get rid of the ( and )
    2. actually insert a copy of the quickpart at each point in the field where you need it. I am assuming that this is what you mean by

    [QUICKPART FIELDNAME]

    1. Surround the first one with double quotes, so you have

    { IF "[QUICKPART FIELDNAME]" = " " " " "[QUICKPART FIELDNAME]" }

    Beyond that, it's a question of what you are trying to achieve and that depends a bit on which type of Document Property it is.

    a. Some of these Document Properties are "traditional" builtin Word properties such as AUTHOR, wrapped in Content controls.

    b. Some are new-style Document properties which are only available as content controls (e.g. Company Fax).

    c. If you are using SharePoint, some may be controls that are set up as part of the document Content Type - their values may be filled in in the Sharepoint library, and so on.

    All these "content control" versions of the properties are designed to update automatically when you change their value in Word, but

    d. the result of the IF field itself will not update automatically (you'll need to select it and press F9, or some such).

    e. in their "content control" form, none of the properties really lets you enter an empty value (not even the type (a) builtin properties). As soon as you do that, the "default text", e.g. [Company Fax] reappears, and that's what will actually be tested in the IF field.

    So the nearest you can usually get is to insert a single space to "empty" the field. I'm guessing that perhaps you want to do this:

    If the property only contains space, insert nothing instead

    Otherwise, insert the value of the property

    In which case, at the very least, the above code needs to change to

    { IF "[QUICKPART FIELDNAME]" = " " "" "[QUICKPART FIELDNAME]" }

    (i.e. change the " " result to a "" result)

    However, that will not catch

    f. the case where the field is completely blank and actually contains the default text,

    g. the case where the field has been blanked using more than one space or other forms of white space.

    I believe you may be able to get around at least the common cases using a set of fields as follows:

    { SET CC [QUICKPART FIELDNAME] }{ IF { =DEFINED(CC) } = 0 "" "{ IF  "[QUICKPART FIELDNAME]" = "[Company Fax]" "" "[QUICKPART FIELDNAME]" }" }

    (all the {} have to be the special field code braces you can insert using ctrl-F9)

    However, I haven't tested that much

    For a builtin property that has an underlying field code such as { AUTHOR }, you should be able to use the property field (not the content control) instead:

    { AUTHOR }

    But as with the IF field, you'll have to update that field to see any change in the property value.

    Was this answer helpful?

    0 comments No comments
  2. Suzanne S Barnhill 278.1K Reputation points MVP Volunteer Moderator
    2012-04-06T23:50:24+00:00

    Don't put a space between the quotes in either Expression2 or the TrueText.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-04-06T21:03:16+00:00

    I'm trying something similar with a word template.docx with Quick Parts Document Property fields.

    I want the field to be blank if the field is empty but display the field otherwise.  I keep getting syntax errors when I build the IF statement like this:

    { IF( [QUICKPART FIELDNAME] =  " "    " "   "[QUICKPART FIELDNAME]")  }

    Is there any way to accomplish what I'm trying to do?

    Thanks

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-08-03T19:25:56+00:00

    Thanks so much for the prompt response.  That solved my problem.  I also notice that the INCLUDEPICTURE field code doesn't work if the path is to a shortcut and not an direct path to the image file.   My .doc is now behaving as I expect.   Thanks again.

    Was this answer helpful?

    0 comments No comments