用户更改父代Drop-Down时如何重置Drop-Down?

时间:2019-10-02 21:16:15

标签: vba ms-word

我的老板希望我在MS Word中创建一个表单,以供用户根据其部门请求访问共享驱动器。该表单具有三个下拉菜单,具体取决于一个父下拉列表,因此,当用户选择一个部门时,该子下拉列表仅显示该特定部门的共享驱动器。 我已经写了,但是问题是在他们从任何子下拉菜单中选择一个选项然后更改了父项之后,子项仍然存在,这是错误的。更改父下拉菜单后,如何重置子下拉菜单? 这是我的代码

Public xDivision As FormField

Sub ConditionalDrives()
    Dim xDrives As FormField
    Set xDivision = ActiveDocument.FormFields("ddDivisions")
    On Error Resume Next
    Set xDrives = ActiveDocument.FormFields("ddDrives")
    If ((xDivision Is Nothing) And (xDrives Is Nothing)) Then Exit Sub
        With xDrives.DropDown.ListEntries
            Select Case xDivision.Result
                Case "Admin"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1\ADMIN"
                    .Add "(H:) \\SHEARDDRIVE2(Confidential Staff)"
                    .Add "(N:) \\SHEARDDRIVE3(Personnel)"
                Case "IT"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1"
                    .Add "(Y:) \\SHEARDDRIVE2"
                Case "HR"
                    .Clear
                    .Add "(F:) \\HRSHEARDDRIVE"
                    .Add "(M:) \\SHEARDDRIVE2"
            End Select
        End With
 End Sub

Sub ConditionalDrives2()
    Dim xDrives2 As FormField
    Set xDrives2 = ActiveDocument.FormFields("ddDrives2")
        With xDrives2.DropDown.ListEntries
            Select Case xDivision.Result
                Case "Admin"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1\ADMIN"
                    .Add "(H:) \\SHEARDDRIVE2(Confidential Staff)"
                    .Add "(N:) \\SHEARDDRIVE3(Personnel)"
                Case "IT"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1"
                    .Add "(Y:) \\SHEARDDRIVE2"
                Case "HR"
                    .Clear
                    .Add "(F:) \\HRSHEARDDRIVE"
                    .Add "(M:) \\SHEARDDRIVE2"
            End Select
        End With
End Sub
Sub ConditionalDrives3()
    Dim xDrives3 As FormField
    Set xDrives3 = ActiveDocument.FormFields("ddDrives3")
        With xDrives3.DropDown.ListEntries
             Select Case xDivision.Result
                Case "Admin"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1\ADMIN"
                    .Add "(H:) \\SHEARDDRIVE2(Confidential Staff)"
                    .Add "(N:) \\SHEARDDRIVE3(Personnel)"
                Case "IT"
                    .Clear
                    .Add "(F:) \\SHEARDDRIVE1"
                    .Add "(Y:) \\SHEARDDRIVE2"
                Case "HR"
                    .Clear
                    .Add "(F:) \\HRSHEARDDRIVE"
                    .Add "(M:) \\SHEARDDRIVE2"
            End Select
        End With
End Sub

0 个答案:

没有答案