Forum Discussion

CAE421's avatar
CAE421
Occasional Reader
Apr 30, 2026
Solved

Conditional field code

Hi, I'm trying to create some conditional code as seen in the screenshot below:

But when I update the field it just shows a field code saying STYLEREF

I need it to insert the paragraph number from the referenced paragraph if it's above 0 and if it's zero I need it to not insert anything.

Where it says "Error!*", I tried removing that and inserting "0" but this had no effect.

I was wondering if someone could help me out?

Thanks in advance.

 

  • You must not type the curly braces! You must generate them using Ctrl+F9 (in my French version). Also, there is a non-breaking space in the error messages (in my version).

     

10 Replies

  • Charles_Kenyon's avatar
    Charles_Kenyon
    Bronze Contributor

    First, if you use Insert > Quick Parts > Field to insert the field, you will not get curly quotation marks. You can undo curly quotation marks using Ctrl+Z to undo autoformat.

    Curly braces {} cannot be typed. You can insert them using Ctrl+F9.

    Here are references on the conditional IF field:

    The switch \* MERGEFORMAT is seldom helpful and can cause problems. 

    Dealing with Fields in Microsoft Word

  • Hecatonchire's avatar
    Hecatonchire
    Iron Contributor

    You must not type the curly braces! You must generate them using Ctrl+F9 (in my French version). Also, there is a non-breaking space in the error messages (in my version).

     

    • CAE421's avatar
      CAE421
      Occasional Reader

      Thank you so much - it was the incorrect curly braces that were causing the problem so all working well now.

    • CAE421's avatar
      CAE421
      Occasional Reader

      Thanks for the reply. The following field code works to insert the numbering for the text with the paragraph style called "Topic name".

      eg. 1.1 Heading name

      If the heading that's styled with "Topic name" has numbering applied then the numbers are inserted. If there is no numbering applied then it inserts zero (0).

      I'm trying to use a conditional if statement to check to see if the numbering is 0 and if yes, then not to insert any numbering at all, including no zero. Here is what I was using:

      I tried to remove the quotation marks as suggester by the other poster and the code looked like this:

      The above gives me the error: 

      Error! Unknown switch argument.

      The resources you suggest don't mentioned IF statements which is why I'm posting here.

      Any further help appreciated.

  • CAE421's avatar
    CAE421
    Occasional Reader

    Thanks for the reply. I removed the quotation marks and the code now looks like the following:

    I get the following when I update the field code:

    Error! Unknown switch argument.

    Do you have any further advice?

     

    • CAE421's avatar
      CAE421
      Occasional Reader

      Thanks for the reply. I removed the quotation marks as suggested but I get the following error:

      Error! Unknown switch argument.

      My code now looks like this:

      Could you provide further advice?

      • gmaxey's avatar
        gmaxey
        Occasional Reader

        { If { STYLEREF  "Topic name"  \n } = 0 ""{ STYLEREF  "Topic name"  \n } }