Resting Anchor

The Anchorage

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

ADCAP Content Control Check Boxes and
Options Buttons

(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!


The purpose of this Microsoft Word Tips & Microsoft Word Help page is to extend the theme of "ADCAP (Advance Capability) Content Controls" and illustrate methods for creating grouped mutually exclusive content control check boxes (which function as option buttons) and grouped check boxes with a defined selection limit.

Background

Typically check boxes shouldn't be used in an exclusive situation and your document user's are expected to check one check box, no check box or all that apply as illustrated below.

cc_option_buttons_1

When option buttons are employed, the user is typically expected to choose, and should be restricted to choosing, only one listed item.

cc_option_buttons_3

Using the content control properties dialog, you can define symbols for the content control check box "checked" and "unchecked" state and make the checkbox resemble option buttons (sometimes called radio buttons):

cc_option_buttons_2

However, "out of the box" there is nothing in Word that limits the user to one selection:

cc_option_buttons_4

Using the methods described in this tips page, you can ensure the user selection is processed in real time and create option buttons in your documents so the user is limited to a single selection as following video illustrates.

Method 1 - Custom Document_ConentControlOnChange Event

Method 1 employs an adaptation of my Content Control Custom Events technique, a careful convention for defining the content control "tag" property, and a little VBA wizardry. 

VBA code in the custom event procedure ensures that only one option button in a defined group can be in the checked state at any given time.

All of the required VBA code is available in the "ThisDocument" module of the VB Project of the template which you can download using the link at the end of this tips page.

While the code may appear daunting to novices, it is really quite simple and works basically like this:

Site Note IconNote:  The optional "Other/Please Specify" shown in the video is a feature of Method 1 and the Add-In only.

Your documents may have one or more mutually exclusive content control option button groups.  The key is the careful application of "tags" to your check boxes and the optional user defined text content controls.

The following illustrates a properly tagged check box used as an option button and a properly tagged optional user defined text content control.

cc_option_buttons_5

cc_option_buttons_6

cc_option_buttons_7

Defining and tagging a large number of content controls can be tedious.  Accordingly, I've created a full featured Word Template Add-In that facilitates creating ADCAP content control  check boxes for you automatically.  The add-in is described in more detail later in this tips page.

Method 2 - Content Control Mapping and Built-In Document Event

Method 2 utilities content control mapping and the pseudo "OnChange" property of the built-in Document_ConentControlBeforeStoreUpdate event.

While this method uses the built-in events, it is significantly more complicated and unfortunately, after hours and hours of testing and experimentation, I discovered that the controls and processes will not perform as expected when the user applies editing restrictions to the document.

Site Note iconNote: The basic concept of this method was proposed by former Word MVP and friend Peter Jamieson.

As with Method 1, all of the required VBA code is available in the "ThisDocument" module of the VB Project of the template which you can download using the link at the end of this tips page.

A complete discussion of content control mapping is beyond the scope of this tips page.  Stated simply, content control mapping is a process of binding content controls to a XML node.  When bound to a node the content control value (or state in the case of checkboxes) is determined by the value of the node.

This method works basically by using the Document_ContentControlBeforeStoreUpdate event to ensure that if any content control check box bound to an attribute child node of an identified parent node is checked, then all other content control check boxes bound to other attribute child nodes of that same parent node are unchecked.

Due to the shortcoming mentioned above, this method is half-baked so to speak, and is only provided for those people who might be interested in the code.  It was not developed further as a functional add-in.

ADCAP Content Control Check Boxes for Word© Add-In

After the big disappointment of discovering method 2 described above fails when employed in documents with editing restriction, I had to change course and further develop method 1.  The tasks was certainly challenging and frustrating at times, but in the end it was rewarding and I think the effort was worthwhile.

Site Note Icon For more on template add-ins and how to load them, see: Organizing Your Macros/Template Add-ins at: Installing Macros

When the Add-In is first loaded, a "Disclaimer/Terms of Use" statement is presented which you must accept before proceeding.  After accepting the terms of use, the user interface (UI)appears on the ribbon Add-Ins tab:

cc_option_buttons_8

Site Note IconNote: The controls on the UI may be dimmed and unavailable if there is no active document open or if the document is not compatible with Word 2010 or higher.  Since content control checkboxes were not available in Word before Word 2010, the Add-In will not support documents created in earlier versions.

I have tried to make this Add-In as user friendly as possible and eliminate any need for users to understand or need to deal with VBA coding.  However, each document in which you want to incorporate ADCAP Content Control check boxes, must have specific code in the "ThisDocument" module of document VB project.

The add-in will automatically perform a cursory check for the existence of the correct code when you attempt to create ADCAP Content Control check boxes.

This feature requires access to the document VBA object project module. In order to get access, you must set the option "Trust access to the VBA object module" using File>Options>Trust Center>Trust Center Settings>Macro Settings and then click OK.

cc_option_buttons_15

Site Note IconTo mitigate security risks, after you have created your ADCAP Content Control Check Boxes you should return to the Trust Center and remove access o the VBA project object module.

If the check fails, and the "ThisDocument" module contains no code, the Add-In automatically inserts the required code in the active document "ThisDocument" module.

If the check fails, and the "ThisDocument" module contains code, the Add-In automatically prompts the user to refresh the existing code with the required code.

cc_option_buttons_9

If you click "Refresh Code," the Add-In looks for specific named procedures in the VB project. If a named procedure is not found, the Add-In automatically adds the required procedure. If the named procedure is found, the Add-In prompts the user to replace the found procedure as illustrated below:

cc_option_buttons_12

Clicking "Yes" replaces the procedure. Clicking "No" displays the following user notification:

cc_option_buttons_13

If you click "Cancel" or "No" in the aforementioned dialogs, then I have to assume that you know enough about VBA code to evaluate your existing code and the code required by the Add-In in order to ensure the Add-In features will function as required.

For example, you might have existing code in the built-in Document_ContentControlOnEnter event.  If this is the case you will need to incorporate the required elements of the Add-In Document_ContentControlOnEnter event into your existing event.

Site Note IconNotes: If the check procedure is found, the Add-In "does not" validate that all of the code in your "ThisDocument" module is the correct code.  See: "Clicking Add or Refresh Code" below.

Clicking "Create Controls" opens the Add-In UI (userform dialog)

cc_option_buttons_10

Using this dialog, you:

Site Note IconNotes:

1. To create a group of mutually exclusive option buttons, the cursor must be located in an empty paragraph.

2. When a pre-defined symbol pair is selected, the character number and fonts fields display the character numbers and font names of the the selected pairs.

3. Version 1.1 introduces the pre-defined symbol pair lists.  This feature was prompted by a suggestion by my long time friend Graham Mayor.  In addition to his typical outstanding reviews and comments on my projects, he now seems to enjoy adding a bit of his polish to my projects  as much as I enjoy doing the same to his!   

Group Types

Using the Add-In you can create three types of ADCAP Content Control Check Boxes with a variation of one type.

When groups are defined and added to the document, they are added as a continuous text string in the empty paragraph. After adding, you can relocate and add additional test as required.

Site Note IconNote: In version 1.2. not illustrated below, I replaced the spaces separating the option buttons with tabs. 

cc_option_buttons_11

Clicking "Lock\Add Editors"

After you have gone to the trouble of adding multiple groups of ADCAP Content Control check boxes to a document or template, I assume that you want them to stay there and not be easily deleted by a careless user.

I have also assumed that you will restrict editing in your template\document. See: Content Control Fill-in Form.

This button sets the content control "Content Control cannot be deleted" property on all ADCAP Content Control check boxes in the document and adds a "wdEditorEveryone" editor to the control range.

Clicking "Unlock\Delete"

This button clears the content control "Content Control cannot be deleted" property, if set, and deletes:

Clicking "Remove Editors"

This button removes "ALL" editors for all ADCAP Content Control check boxes in the document.

Clicking "Add or Refresh Code"

Clicking this button simply provides a means to "confirm" and manually load or restore the required code to the default values required by the add-in.

Site Note iconNote: This tips page, illustrations and examples were developed using Word 2010. It is wholly functional with Word 2013.

The rest I think is self explanatory, so that's it! I hope you have found this tips page useful and informative.  You can download the templates containing both methods, the examples used to create this tips page, and the Add-In here: Templates.

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