Share via

Dependent Lists in a Repeating Section Content Control

Anonymous
2020-12-08T22:48:43+00:00

Hi all,

I found a video on the internet that was very helpful with creating a dependent list; however, the only issue is that is not dynamic. Here is my dilemma:

I have my VBA to work where:

  • if Utility = Energy

          Utility Type can equal: "Electricity, Diesel, Natural Gas, Propane ...."

  • if Utility = Water

          Utility Type can equal: "City/Industrial Water, RO/Purified..."

  • if Utility = Waste

          Utility Type can equal: "Hazardous, Non-haz..."

However, it only works when it is not in a Repeating Section content control (RSCC). When it is in the RSCC and the user adds a new row, the Utility box column will change freely, but the Utility Type box will still be dependent on the Utility box in thefirst row:

Utility Utility Type
Energy (Drop down menu) - A1 (Drop down menu) Works
Energy (Drop down menu) - A2 (Drop down menu) Dependent on A1
Energy (Drop down menu) - A3 (Drop down menu) Dependent on A1

I'm not sure how to make it such that it will be dynamic; anytime the user adds a new row, the Utility Type List will be dependent on the Utility adjacent to it, not the parent in the first row, first column

My VBA code is: 

Sub PopulateddStatus()

    Dim xDirection As FormField

    Dim xState As FormField

    On Error Resume Next

    Set xDirection = ActiveDocument.FormFields("Utility")

    Set xState = ActiveDocument.FormFields("UtilityType")

    If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub

    With xState.DropDown.ListEntries

        .Clear

        Select Case xDirection.Result

            Case "Energy"

                .Add "Electricity"

                .Add "Natural Gas"

            Case "Water"

                .Add "RO/Purified Water"

                .Add "City/Industrial Water"

            Case "Waste"

                .Add "Hazardous"

                .Add "Non Hazardous"

        End Select

    End With

End Sub

This solution can be solved in Excel, but for the intended purposes, our company needs it in Word.

Thank you!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2020-12-08T23:27:47+00:00

If you send me a copy of the document\template, referencing this thread in the covering email message, I will see if I can come up with something that will work.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2020-12-09T00:05:11+00:00

    Offline, Doug helped me edit my code to:

    Sub PopulateddStatus()

        Dim xDirection As FormField

        Dim xState As FormField

        On Error Resume Next

        Set xDirection = Selection.Rows(1).Cells(1).Range.FormFields(1)

        Set xState = Selection.Rows(1).Cells(2).Range.FormFields(1)

        If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub

        With xState.DropDown.ListEntries

            .Clear

            Select Case xDirection.Result

                Case "Energy"

                    .Add "Electricity"

                    .Add "Natural Gas"

                Case "Water"

                    .Add "RO/Purified Water"

                    .Add "City/Industrial Water"

                Case "Waste"

                    .Add "Hazardous"

                    .Add "Non Hazardous"

            End Select

        End With

    End Sub

    Thank you!!

    Was this answer helpful?

    0 comments No comments