Forum Discussion

Magnus_Edstrm's avatar
Magnus_Edstrm
Copper Contributor
Dec 16, 2022

templatebuilding

Hi new to the forum and I really don´t know if my question even is feasible but here goes

 

I am making a template that has a pull down list of options. I wonder if it would be possible to connect different sets of informationsfields to each specific choice on the list, so if I was to choose option A the corresponding fields prompting me to fill in the necessary information associated with option A would automatically appear when I made the selection in the list?

 

Sincerely 

 

Magnus Edström

35 Replies

  • Magnus_Edstrm If you had the list entries A, B, C, etc in a Combobox Content Control in the document and you enclose the Form corresponding to each entry in a bookmark A, B, C, etc and you have the following code in the ThisDocument object, when an item is selected in the combobox and the user exits from that combobox, only the form corresponding to the selected item will be visible and the forms corresponding to the other list entries will be hidden.

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    With ContentControl
        If .Title = "ALPHA" Then
            For i = 1 To .DropdownListEntries.Count
                If ActiveDocument.Bookmarks.Exists(.DropdownListEntries(i).Text) Then
                    ActiveDocument.Bookmarks(.DropdownListEntries(i).Text).Range.Font.Hidden = True
                End If
            Next i
            For i = 1 To .DropdownListEntries.Count
                If .DropdownListEntries(i) = .Range.Text Then
                    ActiveDocument.Bookmarks(.DropdownListEntries(i).Text).Range.Font.Hidden = False
                End If
            Next i
        End If
    End With
    End Sub

     

    • Magnus_Edstrm's avatar
      Magnus_Edstrm
      Copper Contributor

      Doug_Robbins_Word_MVP 

       

      This is exactly what I am after. Where do I insert this line of code? and where do I change the value to correspond with the item in the combobox content control?

       

      /Magnus

      • Magnus_Edstrm You should create a macro enabled template (*.dotm) and in the Visual Basic Editor, access the ThisDocument object and paste the code into the Window on the right

         

        The code has been written on the basis that the items in the combobox are identical to the bookmarks in the template so that it is not necessary to refer either to the actual items in the list or to the actual bookmark names and also so that the code will cater for any number of items in the list\bookmarks in the document.

         

        Start by using your examples of A, B, and C to see for yourself that it works.

Resources