View Single Post
 
Old 06-23-2015, 08:44 AM
DougsGraphics DougsGraphics is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Jun 2015
Location: New Mexico
Posts: 2
DougsGraphics is on a distinguished road
Question Clicking the selected Content Control checkbox returns wrong control in vba event

I am perplexed by the behavior of a word 2010 form built using content controls. I have found a very reproducible error that is driving me nuts. To illustrate, the form has a lot of checkbox controls that I use as radio buttons through vba. For example, the word file will have a list of options, each content control having the same title (e.g., "Char") and a sequential ordering of tags built from the title (e.g., "Char-0", "Char-1"...). When one of the items in the list is selected, I use a Select Case statement on the title to know which list, then if the user selected (set the control to true), step through all the items of the list to deselect all the others.

The VBA for a grouping of five such controls would then look like this:

Code:
Private Sub Document_ContentControlOnEnter(ByVal CC As ContentControl)

Dim MyGrp As String
Dim i As Integer
Dim MySelectX As Integer

'get the tag number of the item in the list
If IsNumeric(Right(CC.Tag, 1)) Then
    MySelectX = CInt(Right(CC.Tag, 1))
End If

'Get the base name of the tag group
MyGrp = Left(CC.Tag, InStr(1, CC.Tag, "-"))

Select Case CC.Title
  Case "Char"
     'if user checks box, uncheck all others in list
     If CC.Checked = True Then
       For i = 0 to 4
          If i <> MySelectX then ActiveDocument.SelectContentControlsByTag(MyGrp & i).Item(1).Checked = False
      Next i
   End If

End Select
End Sub
Each time the user selects a control, the control appropriately toggles and the highlight advances to the next control in the form. The behavior I observe is that everything works just fine UNLESS one of the items in the list is already checked, and the user clicks on the selected (highlighted) control. The clicked control appropriately toggles, and the highlight advances to the next, HOWEVER, the content control that is then returned through the event handler is NOT the item the user selected, but instead, the next control in the form. Needless to say, things don't work in that event and you end up with multiple items in the option list selected. It doesn't matter which position in the list is clicked, it is only dependent upon whether the highlighted control is clicked.

Has anyone else observed, and more importantly, overcome this issue?

I've used both the OnEnter and OnExit event handler, and it doesn't make any difference.

Can the advancing of the control field on clicking be somehow disabled, overridden, or forced to return to the control that was clicked? If so, I can devise a work-around, but I haven't figured out how to do that.

Last edited by DougsGraphics; 06-24-2015 at 07:37 AM. Reason: To indicate solved
Reply With Quote