多项查找文本框
multiple item lookup text box
我创建了一个 Access 2010 搜索框,它根据 table 中的列过滤结果,然后根据查询向我显示结果。
我想要实现的目标是一次不仅可以在搜索框中放置一个项目,还可以放置多个项目。
这是我管理的所有路由器,每天我都会得到一个需要检查状态的路由器列表,所以我现在正在做的是将每个路由器名称复制并粘贴到搜索框中,它会给我状态,位置和电路参考,但我想做的是一次性复制并粘贴所有路由器名称,并为每个路由器获得独立的结果。
这是我在文本框中为过滤器申请的代码:
Where Condition = [Circuit Reference] Like "*" & [Forms]![Query1]! [Text12] & "*"
我可以添加更多文本框并将此过滤器应用于它们,但我仍然必须单独复制并粘贴每个路由器名称。
我不是访问大师,所以如果这个问题太容易回答,我深表歉意,但我在网上找不到任何可以帮助我解决问题的东西。
听起来您想在同一个字段上进行多个通配符搜索。您可以通过在 SQL 查询中使用 OR
来执行此操作。
Dim strSearchConditions As String
Dim strTerms() As String
Dim strSQL As String
Dim i as Integer
strSearchConditions = ""
strTerms = Split(Me.txtSearch,",") 'Assuming you separate your search terms with a comma
For i = 0 To UBound(strTerms)
If Not strTerms(i) = "" Then
strSearchConditions = " OR [Circuit Reference] Like '*" & strTerms(i) & "*'"
End If
Next i
If Not strSearchConditions = "" Then
strSQL = "Select * FROM tblMyTable WHERE 1=1 AND (" & strSearchConditions & ")"
Else
MsgBox "No search terms!"
End If
我创建了一个 Access 2010 搜索框,它根据 table 中的列过滤结果,然后根据查询向我显示结果。
我想要实现的目标是一次不仅可以在搜索框中放置一个项目,还可以放置多个项目。 这是我管理的所有路由器,每天我都会得到一个需要检查状态的路由器列表,所以我现在正在做的是将每个路由器名称复制并粘贴到搜索框中,它会给我状态,位置和电路参考,但我想做的是一次性复制并粘贴所有路由器名称,并为每个路由器获得独立的结果。
这是我在文本框中为过滤器申请的代码:
Where Condition = [Circuit Reference] Like "*" & [Forms]![Query1]! [Text12] & "*"
我可以添加更多文本框并将此过滤器应用于它们,但我仍然必须单独复制并粘贴每个路由器名称。
我不是访问大师,所以如果这个问题太容易回答,我深表歉意,但我在网上找不到任何可以帮助我解决问题的东西。
听起来您想在同一个字段上进行多个通配符搜索。您可以通过在 SQL 查询中使用 OR
来执行此操作。
Dim strSearchConditions As String
Dim strTerms() As String
Dim strSQL As String
Dim i as Integer
strSearchConditions = ""
strTerms = Split(Me.txtSearch,",") 'Assuming you separate your search terms with a comma
For i = 0 To UBound(strTerms)
If Not strTerms(i) = "" Then
strSearchConditions = " OR [Circuit Reference] Like '*" & strTerms(i) & "*'"
End If
Next i
If Not strSearchConditions = "" Then
strSQL = "Select * FROM tblMyTable WHERE 1=1 AND (" & strSearchConditions & ")"
Else
MsgBox "No search terms!"
End If