Using MS Word 2010 I am trying to place an INCLUDEPICTURE field into a block of an IF statement. While both the IF statement and the INCLUDEPICTURE work correctly separate, they do not work in combination.
IF Statement:
{ IF { MERGEFIELD condition \* MERGEFORMAT } = "expression" "true" "false" \* MERGEFORMAT }
This works correctly.
INCLUDEPICTURE:
{ INCLUDEPICTURE "picture.png" }
This works correctly, too.
Combination of the two:
{ IF { MERGEFIELD condition \* MERGEFORMAT } = "expression" "{ INCLUDEPICTURE "picture.png" }" "false" \* MERGEFORMAT }
This does not work. If the IF expression is true, nothing is displayed at all.
How can I combine both the IF statement and the INCLUDEPICTURE command?
This is a well known-problem (i.e. you are right, it doesn't work).
Unfortunately, there isn't a particularly good solution - the simplest involves using a blank 1-pixel image file.
The usual starting point is to invert the nesting so that you have something more like this...
This always tries to insert a picture, and will report (and insert) an error in the case where { MERGEFIELD condition } <> "expression". The simplest resolution is to have a blank 1-pixel picture that you can include instead, e.g.
It is sometimes clearer to remove the test and assignment and do it separately, particularly if there are multiple tests. In this case,
or if you prefer,
You still need an IF nested inside the INNCLUDEPICTURE to make it work. You can use:
If you merge those nested fields to an output document, the fields will remain in the output. If you want the fields to be resolved (e.g. because you need to send the output to someone who does not have the image files) then you need something more like this:
I believe you can reduce this to
In fact, I believe you can insert the full path+name of any graphic file that you know exists instead of the first { picname }, e.g.
But you should check that those work for you.
EDIT FWIW, some recent tests suggest that whereas the pictures appear unlinked, a save/re-open displays a reconstituted link (with a *MERGEFORMATINET near the end), and the pictures are expected to be at the locaitons indicated in those links. Whether this is due to a change in Word I cannot tell. If anything has changed, it looks to be an attempt to allow some relative path addressing in the Relationship records that Word creates inside the .docx.
Some observations...
So far, none of these field constructions will deal with the situation where you have path names for pictures that may or may not exist. If that is what you need, please modify your original question.