SOLVED

Adaptive behavior in a form?

Copper Contributor

HI

My problem:
I have a form made in Word, that my colleagues have to fill out relative often, at the beginning of a new task.
The form is pretty long because it has to to be flexible enough to meet everybodys needs. Therefore it has 9 predefined form-sections the user can fill. Often the user only needs to fill one or two of the possible sections. This creates a document thats allways much longer than needed. 

 

The solution I cant use:
The easy solution to that would be to design the form as an online-form, as a simpel survey, that adapts to users needs for txt-response. But, -due to regulations this specifick form must be offline and even not a database.   :(  

A solution in Word???
Can a Word-form behave adaptive according to a user-choice? 
Example:
The user starts to fill tre check-boxes in the first section of the word-form.  Could be...
I need to report an:
- Observation (Checkbox)

- Incident (Checkbox)

- Information (Checkbox)

 

Depending on the checkbox choises, the form the automaticaly adapts and inserts ( or just show/hide) a predefined form-section to fill out? 

6 Replies
If you select each of the sections of the form and identify them by adding a bookmark to each, then you can control whether or not a Section appears by setting the hidden attribute for a section based on the state of the check boxes.
For more specific assistance, we would need to know what type of controls you are using on the form - Content Controls or Legacy FormFields?
@Doug_Robbins_Word_MVP 

Hi
Thx for your reply.
OK. ..Now following your recipe.....

Status on following your recipe:
 - Each section are bookmark as Sec1, Sec2, Sec3 and visa versa. 
- Each section are set to hidden
- Now only checkboxés are visible. 
(Im using content control check box, but thats easely changeble if needed? )

I hope you could show me a way going foreward from here.
I fear :) going foreward includes VB-coding, and to be honest, my VB-capabilities are rudimentary but not 100% absent.

Going foreward we clould keep it as simpel as possible. One checkbox controlling showing/hidding a section. We could use this:

Checkbox are named CB1
Hidden Section are called Sec1
If you could show me a way on that, I can take it futher an implement in the actuel case myself. 



best response confirmed by Keldyding (Copper Contributor)
Solution

@Keldyding 

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. 

Hi
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.
HI 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
Glad to hear that it helped you.
1 best response

Accepted Solutions
best response confirmed by Keldyding (Copper Contributor)
Solution

@Keldyding 

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. 

View solution in original post