View Single Post
 
Old 12-06-2017, 10:29 AM
warbird warbird is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Default Content Control Option Button Oops

I'm using this code to simulate the old option button group with content controls. It works but for one thing. If you miss-click the CC and the curser lands in the table cell the code doesn't run. It's then possible to mark more than one checkbox (which somewhat defeats the purpose). It's an obvious mistake and is easily corrected by clicking on another of the option buttons (assuming you click directly on the CC). The Is there something that can be added to the code to prevent this? Can the Table Cells be locked without effecting the CC's in it?

Code:
Private Sub Document_ContentControlOnEnter(ByVal oCC As ContentControl)
Application.ScreenUpdating = False
  With ActiveDocument
    On Error GoTo NoTally
  With Selection
    If oCC.Tag <> "RateDot" Then
        GoTo NoTally
    End If
    If .Information(wdWithInTable) Then
      Set oTbl = .Tables(1)
      lCol = .Cells(1).ColumnIndex
    End If
  End With
  If oTbl Is Nothing Then GoTo NoTally
    Set oRow = oTbl.Rows(Selection.Cells(1).RowIndex)
    With oRow
      If .Range.ContentControls.Count < 5 Then GoTo NoTally
      If oCC.Type = wdContentControlCheckBox Then
        If oCC.Checked = True Then
          For Each oCel In oRow.Cells
            With oCel.Range
              If .ContentControls.Count > 0 Then
                If .ContentControls(1).Type = wdContentControlCheckBox Then
                  If oCel.ColumnIndex <> lCol Then
                    .ContentControls(1).Checked = False
                  End If
                End If
              End If
            End With
          Next
        End If
      Else
      GoTo NoTally
      End If
    End With
NoTally:
    Set oTbl = Nothing
  End With
Application.ScreenUpdating = True
Exit Sub
End Sub
Reply With Quote