繁体   English   中英

在 Access 中使用多个组合框作为查询条件不能一起使用,但使用一个组合框可以吗? 如何使所有组合框工作?

[英]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?

我看起来当我使用一个组合框作为标准时工作得很好,但是使用更多虽然遵循相同的步骤不起作用。 我不使用 SQL 我确实使用设计视图。

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

如果您希望使用从多个组合框中选择的数据来过滤表单或列表框,那么您将需要根据所做的选择“即时”构建 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

问候,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM