I've got a couple of merge fields that are using this syntax

{ IF {DOCVARIABLE "variable1" } = "" "" "(the {QUOTE 34}{DOCVARIABLE "variable2" }{QUOTE 34})"  }

If variable1 is empty, it should do nothing but it always inserts the 'false' text, like this: (the "variable2"). I have checked the value of variable1 and it is showing as empty. variable2's value always shows.

Have I got the wrong syntax? I've checked over it several times and I'm using the exact same thing elsewhere and it's working. I'm wondering if it's something to do with using {QUOTE 34} to insert quotes, which is confusing Word? Is there another way to escape double quotes?

  • If should be included in {} press Ctrl +F9 – yass Apr 6 '17 at 15:32
  • It is, sorry that didn't copy across for some reason. I'll edit my post. – Syntax Error Apr 6 '17 at 15:45
  • Try { IF {DOCVARIABLE "variable1" } = "" "" "(the" {QUOTE 34}{DOCVARIABLE "variable2" }{QUOTE 34} ")" } – yass Apr 6 '17 at 15:47
  • That half works. It keeps (the and drops the rest if the variable is blank – Syntax Error Apr 6 '17 at 15:50

Use the following:

{ IF {DOCVARIABLE variable1 } = "" "" "(the {QUOTE 34} {DOCVARIABLE variable2 }{QUOTE 34})"  }  

Remove the quotes surrounding variable1 and variable2
Always use Ctrl + F9

  • Before starting the If
  • Before writing DocVariable variable1
  • Before writing DocVariable variable2
  • Quote 34
    Create the variable1 and 2 in Fields before Formula Run your VBA code to set values to the variable and Update Fields
    Keep in mind if variable1 is string empty is ""
    if variable1 is number null is 0
  • I entered it exactly as you said but it still shows (the "") in the document if the variable is empty! I may need to look at different formatting or populate the variable with something else so i can verify its contents – Syntax Error Apr 7 '17 at 9:11
  • Where do you assign values to the variable1 and 2? – yass Apr 7 '17 at 9:13
  • In a C# application that passes all the values to word. I have displayed all the docvariables and can see that this one is empty. The same if statements work elsewhere in the document but don't have the QUOTE 34 parts – Syntax Error Apr 7 '17 at 9:15
  • I have try it with VBA and it gave me (the " Citation") – yass Apr 7 '17 at 9:23
  • Got it working by setting the field to 0, if nothing is entered. Then checking for that instead of blank. I had to use your syntax though – Syntax Error Apr 7 '17 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.