Hi,
I think there's a bug in the way that nested docvariable fields update. I'm posting this here in the hopes that someone has found a way around this (the question is about fields, but I'm using VBA to manipulate them, so I honestly don't know which forum
is best. Fingers crossed.)
The issue (I think) is that a Docvariable field can't be updated if it is not (or would not) be evaluated by the larger expression. In general practice this is probably not a big deal, but I'm trying to check that fields haven't been typed over, and it
is a problem when the value of the docvariable doesn't match its result.
Create three document variables
- In the VBE Immediate Window:
activedocument.Variables("Var1").Value = "dog"
activedocument.Variables("bVar1").Value = "true"
Create some fields
- In the document (all brackets should be created using Ctrl+F9:
{DOCVARIABLE
Var1
\* MERGEFORMAT}
{IF {DOCVARIABLE Var1} =
"dog" "Found a dog!"}
{IF {COMPARE {DOCVARIABLE bVar1}
= "true"} = 1 {DOCVARIABLE Var1} {IF {DOCVARIABLE Var1}
= "giraffe" "giraffe"} }
Update all fields and view their results. You should see:
dog
Found a dog!
dog
As expected. Now, change the value of Var1 to "rabbit":
activedocument.Variables("Var1").Value = "rabbit"
Update all fields and view their results. You should see:
rabbit
rabbit
Toggle field codes, select the very last DOCVARIABLE Var1
field and toggle only it. It is still "dog".
Even if you select that field and update it specifically (rather than as part of a larger selection), it remains "dog".
You can see the problem as well by changing bVar1 to "false" and then changing Var1 again. Now the second-to-last DOCVARIABLE Var1
field will be outdated.
I may be able to work out some logic for ignoring fields that don't directly impact the displayed value in my check. But that seems like a long way to go for what should be
a relatively simple process.
Can anyone propose an alternate solution? Or perhaps replicate/not replicate my results?
Thanks!