![]() |
|
|||||||
|
|
|
Thread Tools
|
Display Modes
|
|
#1
|
|||
|
|||
|
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
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 |
|
#2
|
||||
|
||||
|
Try something along the lines of:
Code:
Private Sub Document_ContentControlOnEnter(ByVal CC As ContentControl)
If CC.Type <> wdContentControlCheckBox Then Exit Sub
Application.ScreenUpdating = False
Dim MyGrp As String, i As Integer, MySelectX As Integer, bChk As Boolean
'get the tag number of the item in the list
If UBound(Split(CC.Tag, "-")) > 0 Then
If IsNumeric(Right(CC.Tag, 1)) Then
MySelectX = CInt(Split(CC.Tag, "-")(1))
Else
MySelectX = ""
End If
End If
'Get the base name of the tag group
MyGrp = Split(CC.Tag, "-")(0) & "-"
Select Case CC.Title
Case "Char"
bChk = ActiveDocument.SelectContentControlsByTag(MyGrp & MySelectX)(1).Checked
'if user checks box, uncheck all others in list
If CC.Checked = True Then
For i = 0 To 4
ActiveDocument.SelectContentControlsByTag(MyGrp & i)(1).Checked = False
Next i
If bChk = False Then
ActiveDocument.SelectContentControlsByTag(MyGrp & MySelectX)(1).Checked = True
End If
End If
End Select
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thanks Paul! That helped me work it out.
|
|
| Tags |
| content control, content control events, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Replace checkbox symbol with check box content control
|
canadansk | Word VBA | 5 | 04-01-2015 08:21 AM |
How to Control Worksheet Event Handler in Module?
|
tinfanide | Excel Programming | 2 | 10-19-2014 09:46 AM |
Deleting a table from a content control -- preserving the content control
|
BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |
| Retrieving content control value | jillapass | Word VBA | 4 | 05-24-2012 05:07 AM |
| Excel ->VB code for Checkbox (control toolbox) | kirkstyle | Excel | 0 | 08-16-2006 04:17 PM |