使用visualbasic。在搜索了一个又一个答案之后,我的过滤器只从“配方”字段中进行选择。我想输入'鸡蛋'到我的txtsearch文本框,并让我的按钮给所有配方中有'鸡蛋'或作为文本的成分。目前只输出2个结果:蛋诺和蛋本尼迪克特。我也想展示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
1条答案
按热度按时间iezvtpos1#
一个选项是连接所有可能包含您要查找的内容的sql字段,然后在where like….中生成结果。。。。还有一些sql环境使用%作为通配符。