Resting Anchor

The Anchorage

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

Content Control Grouping & Navigation
(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!


This Microsoft Word Tips & Microsoft Word Help page supplements several other content control tips pages. This page focuses on grouping controls so that users are restricted to editing only the content control content and tips for navigating between the controls in a document. See my Content Controls introduction/summary page for a list of links to all content control related pages on this website

Content controls are managed from the "Controls" group in the ribbon "Developer" tab. This group contains command controls for inserting each of the Content Controls types in the document, controls for opening the control design and properties dialogs, and a control for grouping or ungrouping a collection of content controls.

Site Note IconNote:  Developer tab display is optional and hidden by default in Word 2007.  If not displayed check Word Options>Popular>Show developer tab in the Ribbon (Word 2007)/Options>Customize the Ribbon>check Developer tab in right hand column (Word 2010)

cc nav 1

Site Note IconBonus Tip:  Classic Form Controls is a simple Word template add-in to restore the classic form field controls to the ribbon.

Free text

The illustration below shows three plain text content controls arranged with free text in a document. The first control is shown selected. As shown, the text is unrestricted. The user could select and freely edit any portion of the example text.

cc nav 2

The "Properties" dialog is used to assign properties (e.g., name, tag, etc.) to individual controls. The following illustrates the properties set for the content control selected above.  Note there are no locking properties set.  Users can freely edit the content controls and surrounding text.

cc nav 3

Grouping Content Controls

By grouping a collection of content controls the user has access to enter information in the controls but editing other text is restricted. There are two ways that you can group controls:

  1. Using the Group command. To group using the Group command you first select the controls and text to include in the group and click "Group" from the Group command drop down menu.
  2. Nesting controls in a restricted content rich text control container. To group controls by nesting the controls in restricted content rich text control container, you first select the controls and text to include in the group and then click the "Rich Text" add control.
cc nav 4

cc nav 5

After adding the rich text control as shown above, you set its properties to restrict editing content.

cc nav 6

Site Note IconNote: The rich text "Contents cannot be edited" property does not affect or restrict editing in other content controls grouped or (nested) within the rich text control.

Groups appear similar within the document using both methods and work equally well. However, I prefer to use the rich text control method as the control can be assigned a unique group name using the properties dialog and when the control is physically active in the document the group name and boundaries are displayed.

cc nav 7

Navigating between controls

Navigation between individual or grouped plain text, drop-down list, combo box, or date picker controls is accomplished by simply depressing the Tab key. Unlike with legacy form fields, when you tab in the last content control in a sequence the focus is not returned to the first control in the sequence.

Site Note IconNote: To create a tab space in a plain text control use CTRL+Tab.

You can overcome this nuisance by assigning a unique "tag" property to the first and last content control in your sequence and adding the following code to the Document_ContentControlOnExit event procedure:

VBA Script:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Select Case ContentControl.Tag
    '"Last" = tag property applied to the last control.
    Case "Last"
       '"First" = tag property applied to the first control.
       ActiveDocument.SelectContentControlsByTag("First").Item(1).Range.Select
  End Select
lbl_Exit:
  Exit Sub
End Sub

Unfortunately navigating between content controls in documents containing rich text or picture content controls is more problematic.

Rich text controls

First let's look at problems associated with rich text controls. The following example shows three rich text content controls grouped (nested) in a restricted content rich text control container.

Using the tab key in one of these controls enters a physical tab in the control as expected.  The focus does not advance to the next control.

cc nav 8

cc nav 9

To the dismay of many, there is no apparent key stroke that will navigate to the next rich text content control in a document.

Fortunately there is a limited work around. If you can use a table in your document layout with a single rich text control per cell, then you can take advantage of Word's built-in overriding "NextCell" command to move from on cell to another and by extension, one rich text content control to another.

The following example shows three rich text content controls arranged in a borderless table and grouped (nested) in a restricted content rich text control. When working in a table, the built-in "NextCell" command overrides the tab key to move to the next cell in the table.

cc nav 10

Site Note IconNote: Using the method above users would create a physical tab in the control using CTRL+Tab.

The method above may suit many layout requirements. However, if your layout is more complicated then there are more obstacles to overcome. Group Demo 3 is repeated below with followed by additional text and a plain text content control.

cc nav 11

When the user finishes the entry in the last content control of the table and presses tab the operating system returns a default beep and Word refuses to advance to the next content control. Why does this happen?

Remember, while in a table and the user presses "tab" Word executes the "NextCell" command. This command moves the focus to the next cell or if a next cell doesn't exist it creates a new row in the table. In this example, there is no next cell and Word is attempting to create a new row. Since the properties of rich text content control group container (the control containing the group and the table) is set to not allow editing of content, Word can't add the row!! Nothing happens and the system beeps.

We're facing a conundrum as appear to be stuck. Pressing the tab key does not move to the next control or exit the table.

The work around for this problem is more complex. We need to give Word the opportunity to advance out of the last rich text content control in the group, but we don't want to give it free rein to continually add rows to the layout table. We need to provide a means to exit the table and move the focus to the next content control. Using the "Group Demo 3" again, the first step is to add a new placeholder final row to the table layout.

Site Note IconNote: While performing these steps you need to have the group rich text control property set to allow editing content.

cc nav 12

In the placeholder row, add a new plain text content control. Use the content control properties dialog assign a unique "tag" to the control. I named the control "Exit Point" and tagged it "GrpDemo3EP" (for Group Demo 5 exit point).

cc nav 13

cc nav 14

Site Note IconNote:  Content control tags provide a handy call to a particular content control.

Using Table Tools Layout, set the height of the placeholder row to 1 pt. This makes the placeholder row nearly transparent in the document while the placeholder row and "Exit Point" content control provides a target for "NextCell" when the user presses the tab key.

cc nav 15

Next we provide the boost out of the table. When the user tabs from the last rich text control the built-in "NextCell" command sets the focus to our placeholder "Exit Point" plain text content control. At this point we take advantage of the ContentControlOnEnter Event to automatically advance to the next control following the table.

Before doing that, we have to define unique target tag for that control. For this example I used the tag "GrpDemo3NC" (for Group Demo 3 Next Control).

Select the target control and use the properties dialog to define a name and tag.

cc nav 16

cc nav 17

Finally we need to create the ContentControlOnEnter event procedure. Open the VB Editor (ALT+F11) and enter the code shown below into the ContentControlOnEnter Event

VBA Script:
Select Case ContentControl.Tag
Case "GrpDemo3EP"
ActiveDocument.SelectContentControlsByTag("GrpDemo3NC").Item(1).Range.Select
End Select

Your event procedure should look like this:

cc nav 18

When the user tabs from the last valid rich text control in your table layout the focus is shifted to the placeholder content control titled GrpDem3EP. With this shift in focus executes the  ContentControlOnEnter document event.  Code in the event determines that the Grp3DempEP content control has been entered and immediately shifts the focus to the Grp3DemoNC content control outside the table.

Ok not a walk in the sub, but with careful layout and application of exit point and next control point tags, you should be able to create complex layouts using tables and rich text content controls.

Picture controls

The problem associated with picture controls is the most complex and I have not been able to find a reliable work around.

When a user tabs into a picture content control the selection is focused on a drawing object. In Word, when a drawing object is selected the tab key functions to select the next drawing object (not the next content control).

I am not aware of a built-in "NextDrawingObject" command or how to intercept this built-in behavior to tab to the next content control.

We should be able to use the ContentControlOnExit Event and add appropriate action and target tags as shown below. In this example the picture control is tagged "Pic1" and the following control tagged "NCAP1" (for Next control after Pic 1). The OnExit Event code is:

VBA Script:
Select Case ContentControl.Tag
  Case "Pic1"
    ActiveDocument.SelectContentControlsByTag("NCAP1").Item(1).Range.Select
End Select

This method works, but works intermittently. In the majority of trials the next tagged and targeted control is selected, however sometimes the event doesn't fire and the next drawing object is selected instead.

cc nav 19

Site Note IconNote:  The method described above seems to be more reliable in Word 2010.

That's it! I hope you have found this tips page useful and informative. You can use the following link to download a Word document containing the content controls and examples used in creating this tips page: Content Control Grouping and Navigation

Share Stumbleupon

PAYMENTS/DONATIONS

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

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.


Search my site or the web using Google Search Engine

Google Search Logo

Or

JustAnswerAsk a Word Expert OnlineSubmit