使用 Access 表单过滤表中的数据并在组合框中选择一个值

问题描述 投票:0回答:0

我正在研究 Access Tracker,基本上它有一个表格和表格。表的列标题是父实体、子实体、合规性等,表单中的组合框是 parententity2、subs2、compliance2 等。表中的每个父实体可以有多个子实体。我写过这样的代码,当我以 parententity2 的形式选择一个值,然后它会自动填充其余信息。但是,当父项有多个子项时,它现在显示所有值,而不是显示列表中的第一个值。例如 ABC 是母公司,A1、B1、C1 是子公司。然后输出是当我过滤 ABC 然后在子下拉列表中我只能看到 A1,而不是 A1、B1、C1

Private Sub Subs2_AfterUpdate()

Dim strFilter As String

Dim abc


    ' Get the selected value from the parententity2 combo box
    'Dim strFilter As String
    strFilter = Me.Parententity2.Value
    
    ' Apply the filter to the form's record source
    Me.RecordSource = "SELECT * FROM [Data] WHERE [parent entity] = '" & strFilter & "'"
    
    ' Populate the Subs column with the filtered data
    Me.Subs2.RowSource = "SELECT DISTINCT [subs] FROM [Data] WHERE [parent entity] = '" & strFilter & "'"
End sub
vba ms-access ms-access-2010 vba6
© www.soinside.com 2019 - 2024. All rights reserved.