View Single Post
 
Old 08-03-2023, 02:02 AM
Ikeg Ikeg is offline Windows 11 Office 2021
Novice
 
Join Date: Aug 2023
Posts: 3
Ikeg is on a distinguished road
Default Word VBA nested fields show based on checkbox

Hi,

I got the following code from this forum.
Now i have nested fields end everytime i check a checkbox in a nestedfield it auto unchecks again.

Is it possible to have nested fields that show based on a checkboxes?

For example.
Checkbox 1 checked = Show table with content. In that table there are some questions and another checkbox (Checkbox 2) if checked it will show extra content.

Code:
Option Explicit
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim Val As Long

With CCtrl
  Select Case .Title
    Case "Checkbox1", "Checkbox2", "Checkbox3", "Checkbox4", "Checkbox5", "Checkbox6", "Checkbox7", "Checkbox8":
        ActiveDocument.CustomDocumentProperties("Chk" & Right(.Title, 1)).Value = (.Checked = True) ^ 2
        ActiveDocument.Fields.Update
  End Select
End With
End Sub
Thanks in advance!
Reply With Quote