Forum Discussion
Adaptive behavior in a form?
- Jan 13, 2022
To make the code a bit simpler, I would suggest that each section of the form be in a separate Section of the document - Form section 1 in Document Section 2, Form section 2 in Document Section 3, --- Form section 8 in Document Section 9, Form section 9 in Document Section 10, and you have the Nine check boxes in Section 1, with the Titles of the Check boxes being Section 1, Section 2, --- Section 8, Section 9.
Then, in Visual Basic Editor in the ThisDocument object insert the following code
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) Dim Secnum As Long For Each CC In ActiveDocument.ContentControls If Left(CC.Title, 7) = "Section" Then Secnum = Mid(CC.Title, 9) If CC.Checked = True Then ActiveDocument.Sections(Secnum + 1).Range.Font.Hidden = False Else ActiveDocument.Sections(Secnum + 1).Range.Font.Hidden = True End If End If Next End SubThen, if you have the display of Hidden text disabled (Via File>Display) when you check any of the text boxes and exit from the text box, the code will format the text of the Section of the document for which the associated checkbox is checked so that the font is not hidden and for any Section for which the associated checkbox is not checked so that it is hidden and will not therefore appear.
Unfortunately, while a macro enabled workbook (xlsm) can be attached to a response, a macro enabled Word document or template cannot be attached. If you contact me at dougrobbinsmvp[atsymbol]gmail[dot]com, I will send you the macro enabled template that I created to respond to your question.
To make the code a bit simpler, I would suggest that each section of the form be in a separate Section of the document - Form section 1 in Document Section 2, Form section 2 in Document Section 3, --- Form section 8 in Document Section 9, Form section 9 in Document Section 10, and you have the Nine check boxes in Section 1, with the Titles of the Check boxes being Section 1, Section 2, --- Section 8, Section 9.
Then, in Visual Basic Editor in the ThisDocument object insert the following code
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim Secnum As Long
For Each CC In ActiveDocument.ContentControls
If Left(CC.Title, 7) = "Section" Then
Secnum = Mid(CC.Title, 9)
If CC.Checked = True Then
ActiveDocument.Sections(Secnum + 1).Range.Font.Hidden = False
Else
ActiveDocument.Sections(Secnum + 1).Range.Font.Hidden = True
End If
End If
Next
End Sub
Then, if you have the display of Hidden text disabled (Via File>Display) when you check any of the text boxes and exit from the text box, the code will format the text of the Section of the document for which the associated checkbox is checked so that the font is not hidden and for any Section for which the associated checkbox is not checked so that it is hidden and will not therefore appear.
Unfortunately, while a macro enabled workbook (xlsm) can be attached to a response, a macro enabled Word document or template cannot be attached. If you contact me at dougrobbinsmvp[atsymbol]gmail[dot]com, I will send you the macro enabled template that I created to respond to your question.
I see...Using the hidde/show of Document Sections. I allready tried that but only with partial succes 🙂 I think I need to see your macro enabled template to get to the point I want. I will post a PM to your mail. Again thx, for taking time to help me out.
- KeldydingJan 18, 2022Copper ContributorHI Doug
Sooo nice to se how simple, short and elegant a solution can be, when its done by someone knowing what he´s doing. Thx. for speeding your time helping me out.
Keld- Jan 18, 2022Glad to hear that it helped you.