【问题标题】:Using multiple Combo-boxes in Access as query criteria dont work together but using one combo-box works ?? How to make all Combo-boxes work?在 Access 中使用多个组合框作为查询条件不能一起使用,但使用一个组合框可以吗?如何使所有组合框工作?
【发布时间】:2020-04-19 10:01:40
【问题描述】:

当我使用一个组合框作为标准时,我看起来效果很好,但是使用更多,尽管遵循相同的步骤不起作用。我不使用 SQL,但我使用设计视图。

如何使所有组合框协同工作以提供所需的标准。

【问题讨论】:

    标签: ms-access combobox


    【解决方案1】:

    如果您希望使用从多个组合框中选择的数据来过滤表单或列表框,那么您需要根据所做的选择“即时”构建 RowSource。

    下面是一些示例代码,它使用来自 2 个组合框(cboCountry 和 cboRMZone)的选择来为列表框(lstCountry)创建 RowSource:

    Private Sub cboCountryZone_AfterUpdate()
        Call sSearchMultiple
    End Sub
    
    Private Sub cboRMZone_AfterUpdate()
        Call sSearchMultiple
    End Sub
    
    Private Sub Form_Load()
        Call sSearchMultiple
    End Sub
    
    Private Sub sSearchMultiple()
        On Error GoTo E_Handle
        Dim strSQL As String
        If Not IsNull(Me!cboCountryZone) Then strSQL = strSQL & " AND CountryZone_PK=" & Me!cboCountryZone
        If Not IsNull(Me!cboRMZone) Then strSQL = strSQL & " AND RMZone_PK=" & Me!cboRMZone
        If Left(strSQL, 4) = " AND" Then
            strSQL = " WHERE " & Mid(strSQL, 6)
        End If
        If Len(strSQL) > 0 Then
            Me!lstCountry.RowSource = "SELECT CountryName FROM dbo_svr_Country " & strSQL & " ORDER BY CountryName ASC;"
        Else
            Me!lstCountry.RowSource = "SELECT CountryName FROM dbo_svr_Country ORDER BY CountryName ASC;"
        End If
    sExit:
        On Error Resume Next
        Exit Sub
    E_Handle:
        MsgBox Err.Description & vbCrLf & vbCrLf & "Form3!sSearchMultiple", vbOKOnly + vbCritical, "Error: " & Err.Number
        Resume sExit
    End Sub
    

    问候,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      相关资源
      最近更新 更多