We help IT Professionals succeed at work.

How to avoid printing empty metadata in Microsoft Word

Hello,
I have a set of templates in Microsoft Word - in which I do not want empty Quickparts to be printed / previewed.
My templates are linked to a Sharepoint 2010 site, and are populated with metadata from this site, but some of the quickparts will not have data from time to time.
Is there a way / technique in Word to hide / clear / suppress empty placeholders / Metadata fields when the document is printed ?
I do not want the placeholders / quickparts to be removed from the document, as they might have data the next time the document is printed.

As an example i have a SP Metadata named 'ProjectNumber'
The document displayes:   Project:  [ProjectNumber]      when the metadata is empty.
I would like the '[ProjectNumber]' text to be hided upon printing.

Hope this is understandable :-)

Regards,
Tor Arne Litlere
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Awarded 2010
Commented:
Hello,

Yes, this is possible by wrapping the quick part fields into IF field codes in Word.

Scenario: The Word doc has three custom columns in SharePoint
- Customer Title (contains Mr, Mrs, Miss, Ms or is empty)
- First Name
- Last Name

The goal is to have a greeting line

Dear Mr Bloggs  (if the Customer Title has a value)
Dear Joe Bloggs (if the Customer Title is empty)

When you insert the metadata field into a word document, it looks like this when it is empty

[Customer Title]

and like this when a value is selected

Mr

What you need to do is create an IF statement in Word, in pseudo code this looks like:

If [Customer Title] is empty, print the first name, else print the Customer Title. After that print the last Name.

The syntax for a Word IF field is { IF Condition "print when true" "print when false"}

Ready? Let's go. Open your document.

- Hit Alt-F9 to show all field codes in full
- Hit Ctrl-F9 to insert an empty field. It will look like this: { }
- Click inside the brackets and type IF followed by a space and double quotes, so it looks like { IF "}
- With the cursor still inside the brackets, go Insert > Quick Parts > Document Property > Customer Title.
- You should now see { IF "[Customer Title]}
- continue inside the brackets and type closing quotes, followed by  = "[Customer Title]"
- this last bit is NOT a quick part, but you type the square brackets and the SharePoint column name.
- So far we have built the condition. This is what it should look like (the text in italics below is the Quick Part, the other text in square brackets is just text):

{ IF "[Customer Title]" = "[Customer Title]" }

Now for the True part (what should be done if the condition is true? Print First Name.)

- continue with a quote sign, then insert the Quick Part for First Name
- close the quote
- continue with the False part (if we have a customer title, we want to print that)
- enter a quote sign, insert the quick part for Customer Title and close the quote

The complete IF statement should look like this (quick parts are in italics, everything else is text)

{ IF "[Customer Title]" = "[Customer Title]" "[First Name]" "[Customer Title]" }

Enter a space and insert the Quick Part for Last Name.

To test, hit Alt-F9. Select all text and hit F9 to refresh. Open the Document Information panel and play with the contents of Customer Title. Select all text and hit F9 to refresh after each change.

Hope that helps,

cheers, teylyn
CERTIFIED EXPERT
Most Valuable Expert 2011
Awarded 2010
Commented:
Coming back to your own example:

>>The document displayes:   Project:  [ProjectNumber]      when the metadata is empty.


Project: { IF "[ProjectNumber]" = "[ProjectNumber]" "" "[ProjectNumber]" }

cheers,

Author

Commented:
Fantastic !
Very easy and clean solution - spot on for my need :-)
Thanks a lot for very quick respond and detailed explanation.