Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Link "Conditional Content" to a List Selection
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

This Microsoft Word Tips & Microsoft Word Help page consolidates and expands on methods methods previously published on this website for linking document conditional content to a selection made in a document list control.

Conditional Content

Conditional content is variable content determined or defined by a condition. When a document user selects an entry (e.g., person's name) from a document list control, they have created a condition.

As the document designer you may want to link that condition to variable data (e.g., an address and phone number associated with the person selected) as illustrated in the following video.

Considerations

The video illustrates an advanced method using a content control dropdown list and two plain text content controls "content ranges" to display the conditional content.  It works brilliantly for me. If you, as the document designer, have access to Word 2007 or higher it could work for you.

It is completely useless if the document user is limited to Word 2003 (and lower) or not permitted to enable and run macros!

This tips page provides multiple methods for linking conditional content to the following list control types:

All of the methods except one of the formfield methods requires some VBA (macro) to run.

When considering which method is best (if any) to employ in your document design, you should keep the document user and his/her limitations and restrictions in mind.

Linking Methods

Each of the methods for the four types of list controls is demonstrated and fully described in a four part series of demonstration documents.  You can download the documents here or using the link at the end of this tips page.

Working with the demonstration documents

Each of the demonstration documents contain a VBA code module and one or more "content ranges."

Site Note IconNote: "Content ranges" refers to the target, or holder, of the conditional content displayed in the document.  These include fields, document variables, bookmarks, table cells, formfields, content controls, and ActiveX controls.

VBA Project

The VBA project can be accessed by pressing ALT+F3 to open the Visual Basic Editor (VBE). With the VBE open, press Ctrl+r to display the Project Explorer then look for and expand the project.

linked_conditional_content_5

In addition to the "ThisDocument" module, each project will contain one or more standard modules and a form module.  Dbl-click to expand and view the modules.

Use can set stops in the code by clicking in the gray horizontal bar on the right side of the large code editing pane.  When the code is executed, it will run to the stop.  You can then step through and observe the code processes using the F8 key.

linked_conditional_content_6

Code executes OnExit from a document content control



When executed, the code runs until the stop point and the stops.
You can then step through the code line by line using F8
When you've seen enough, you can return to automatic execution by pressing F5.

Fields

Fields (e.g., IF and DocVariable) can be created with the user interface (e.g., Insert>QuickParts>Field) or directly using CTRL+F9.

Field code/results can be toggled globally in the document using Ctrl+a (select all) followed by ALT+F9.

Bookmarks

Bookmarks are created and viewed with the user interface Insert>Links>Bookmark control.

FormFields (Legacy) and ActiveX Controls

Formfields and ActiveX controls are created using the Developer>Controls>Legacy Tools gallery.

linked_condtional_content_7

Formfield properties are defined by dbl-clicking the formfield in unprotected mode.

linked_condtional_content_8

ActiveX control properties are set using the Developer>Controls>Design Mode and right clicking on the control.  Lists are defined using code in the project module.

linked_conditional_content_9

Content Controls

Content controls are created and properties set using the Developer>Controls group and the group "Properties" control.

linked_conditional_content_10

Static/Dynamic List & Variables

Each of the demonstration documents describes methods for employing short static fictional list entries and variable conditional content directly in the control or associated VBA code.

For longer lists, dynamic methods using external data (e.g., Word table, Excel worksheet) are provided.  The following illustrates the content of the external Excel file used in the demonstration documents.

linked_conditional_content_4

Site Note IconNotes:  For the dynamic list features to work, you will need to save the companion Excel file "Data Store.xlsx" with demonstration documents in the same folder on a local drive.  Attempting to use the dynamic features when the files are stored on a cloud drive such as OneDrive results in a run-time error.  I'll update this page if I find a solution to the error.

Linked Lists

Each of the demonstration documents illustrates a method to link the condition created in a primary list to a dependent secondary list.  The following videos illustrates the formfield (legacy) dropdown list method:

Site Note IconNote: Unlike the advance content control method illustrated in the first video, all of the formfield methods and most of the content control methods requires a user initiated exit event before the conditional content is displayed.

LOOK MOM, NO CODE! (but it isn't easy)

The Formfield method demonstration document illustrates the only method to link conditional text that does not require VBA (enabled macros).  This method relies on the "Calculate on exit" property of the formfield to update what can easily become a very complex nest of conditional IF fields.  The representative field code to display the required address and phone number for a there (3) item list is illustrated below:

linked_conditional_content_1
Demonstration document with field codes displayed

linked_conditional_content_2

Content Ranges

VBA code is provided in each of the demonstration documents to populate conditional text in several different content ranges. The Userform demonstration document provides comprehensive methods for populating:

linked_conditional_content_3

The Content Control demonstration document provides a method for to link and display content other than text (e.g., graphics).  This method can be difficult to setup but the result shown in the following video may be worth your effort.

Site Note IconNote: The Content Control demonstration document VBA project contains a special code module "Accessibility" and a procedure that forces that forces the "Developer" tab to display if used with Word 2007. This is required to work around the bug described in my Content Controls tips page.

Conclusion

That's it! I hope you have found this tips page and the companion demonstration documents useful and informative.  Download the demonstration document set here:  Demonstration Document Kit

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo