【问题标题】:Use one filter value to search and output several fields使用一个过滤器值搜索并输出多个字段
【发布时间】:2020-11-24 17:28:08
【问题描述】:

使用 Visual Basic。 搜索并搜索答案后,我的过滤器仅从“食谱”字段中进行选择。我想在我的 txtSearch 文本框中输入“egg”,并让我的按钮给出所有在食谱中有“egg”的食谱或作为成分中的文本。目前只输出 2 个结果:egg nog 和 egg benedict。我也想展示 15 种鸡蛋食谱。

Private Sub Search_Button_Click()

On Error GoTo Search_Button_Click_Err

Dim strSQL As String

    strSQL = "[Cocktail] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing1] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing2] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing3] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing4] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing5] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing6] like '*" & [Forms]![Find]![txtSearch] & "*'" & _
    " Or [Ing7] like '*" & [Forms]![Find]![txtSearch] & "*'"

If Len(strSQL) > 255 Then
   MsgBox "ApplyFilter string length exceeds 255 characters"

Else
   DoCmd.ApplyFilter "", strSQL

End If

Search_Button_Click_Exit:
    Exit Sub

Search_Button_Click_Err:
    MsgBox Error$
    Resume Search_Button_Click_Exit

End Sub

【问题讨论】:

  • 考虑澄清您正在使用的特定数据库(SQL Server、MySQL 等)以及特定的编程语言(VB、C# 等)。您可以通过在问题中使用附加标签来做到这一点。
  • 谢谢你,jmm312。

标签: sql vba forms filter field


【解决方案1】:

一个选项是连接所有可能包含您要查找的内容的 SQL 字段,然后在 where xxx like .... 还有一些 SQL 环境使用 % 作为通配符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    相关资源
    最近更新 更多