使下拉字段相互依赖

make drop-down fields dependent of each other

我设置了一个包含项目详细信息的表单,并希望实现多个下拉选项来过滤项目属性。它们是 "project-name"、"customer" 和 "product"。我想让他们互相依赖。所以当我 select 一个特定的客户时,我只想能够从与客户相关的产品中进行选择。

到目前为止,我能够为每个项目设置每个下拉菜单 属性,但它们不是彼此依赖的,但始终显示所有可用选项。有人可以帮我解决相关的下拉字段吗?

Selection fields as they are now

编辑:Table 根据要求布局:

Rows/format
-项目 ID/Number
-Customer/String
-Product/String
-Project-name/String
-Comment/String
-特征 1/字符串

一种方法是使用 "cascading" 组合框,这样用户就可以从顶部的组合框移动到底部的组合框,每次都缩小他们的可用范围。

您的 VBA 代码将如下所示:

Private Sub cboCustomer_AfterUpdate()
    Dim strSQL As String
    If Len(Me!cboCustomer) > 0 Then
        strSQL = "SELECT DISTINCT Product FROM tblProject " _
            & " WHERE Customer='" & Me!cboCustomer & "' " _
            & " ORDER BY Product ASC;"
        Me!cboProduct.RowSource = strSQL
    Else
        strSQL = "SELECT DISTINCT Product FROM tblProject ORDER BY Product ASC;"
    End If
End Sub

Private Sub cboProject_AfterUpdate()
    Dim strSQL As String
    If Len(Me!cboProject) > 0 Then
        strSQL = "SELECT DISTINCT Customer FROM tblProject " _
            & " WHERE ProjectID=" & Me!cboProject _
            & " ORDER BY Customer ASC;"
        Me!cboCustomer.RowSource = strSQL
        strSQL = "SELECT DISTINCT Product FROM tblProject " _
            & " WHERE ProjectID=" & Me!cboProject _
            & " ORDER BY Product ASC;"
        Me!cboProduct.RowSource = strSQL
    Else
        Me!cboCustomer.RowSource = "SELECT DISTINCT Customer FROM tblProject ORDER BY Customer ASC;"
        Me!cboProduct.RowSource = "SELECT DISTINCT Product FROM tblProject ORDER BY Product ASC;"
    End If
End Sub

此致,