Checkboxes active dependent on other checkboxes

Hello all:

I have a table in MS Word 2010 with 10 columns.  In Col 2. I have a check box.  In Cols 5-10 There are also check boxes.  I would like the check boxes in Cols5-10 to be inactive if the check box in Col 2 is not checked.  I have searched for VBA code but cannot find any.  ALso, it appears that I cannot set up dependencies using the normal controls.

Note:  Not all of the cells in each row has a check box:

Example

Col 1

Col2

Col3

Col4

Col5

Col6

Col7

Col8

Col9

Col10

 

CheckBx

 

 

CheckBx

CheckBx

 

 

 

 

 

CheckBx

 

 

 

 

 

CheckBx

CheckBx

 

 

CheckBx

 

 

 

 

CheckBx

 

CheckBx

 

Answer
Answer

I'm glad you mentioned the compatibility requirement, because that eliminates the possibility of using content control checkboxes. They were first introduced in Word 2010. If you use Word 2007 to open
a document that contains those checkboxes, they'll appear as boxes but they won't be active.

I assume you want users to be able to enter things in the other parts of the table and/or the rest of the document (i.e., it isn't just a form with only those checkboxes). In that case, it will be
easier to work with ActiveX checkboxes, which don't require protecting the document for forms. As I mentioned, those are inserted from the bottom row of the dropdown from the Legacy Tools button in
the Controls group. When you insert one, Word turns on the Design Mode button in the top right corner of the group; if it doesn't also open the Properties pane, click the Properties button to do so.
That pane will show the name of the selected checkbox, which you can change in the row labeled (Name).

For simplicity, insert the checkboxes in column 2 first, in order, so by default they're named CheckBox1, CheckBox2, and so on. Then insert the rest of the boxes; it doesn't matter much what their
names are. When you have all of them inserted, you can close the Properties pane and toggle off the Design Mode button.

Then put code like the following into the ThisDocument module of the template:

Private Sub CheckBox1_Click()
    ' row 2
    EnableDisable CheckBox1, 2
End Sub

Private Sub CheckBox2_Click()
    ' row 3
    EnableDisable CheckBox2, 3
End Sub

Private Sub CheckBox3_Click()
    ' row 4
    EnableDisable CheckBox3, 4
End Sub

' Add more like the above, one for each row that contains a checkbox in column 2

Private Sub EnableDisable(controlCB As Object, row As Integer)
    Dim oTbl As Table
    Dim col As Integer

    Set oTbl = Selection.Tables(1)
    If controlCB.Value Then
        For col = 5 To 10
            With oTbl.Cell(row, col)
                If .Range.InlineShapes.Count = 1 Then
                    .Range.InlineShapes(1).OLEFormat.Object.Enabled = True
                End If
            End With
        Next
    Else
        For col = 5 To 10
            With oTbl.Cell(row, col)
                If .Range.InlineShapes.Count = 1 Then
                    .Range.InlineShapes(1).OLEFormat.Object.Enabled = False
                End If
            End With
        Next
    End If
End Sub

If you change the names of the checkboxes in column 2, make the same change in the corresponding _Click() subroutine. Also, if you need to change which columns contain checkboxes that become
enabled/disabled, change the numbers in both "For col" statements.

Note that if a checkbox in columns 5 to 10 is checked and then you uncheck the box in column 2 of the same row, that will NOT uncheck the disabled box -- and you won't be able to uncheck it unless you
first re-check the column 2 box. If you want all disabled boxes to be cleared, that will take one more line of code.


Jay Freedman
MS Word MVP  FAQ: http://word.mvps.org
_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated December 15, 2023 Views 5,622 Applies to: