Sql 在MS Access中使用包含多个搜索选项的组合框查询一个表的最佳方法是什么?

Sql 在MS Access中使用包含多个搜索选项的组合框查询一个表的最佳方法是什么?,sql,ms-access,vbscript,vba,Sql,Ms Access,Vbscript,Vba,我是新手,所以不要对我太苛刻。我现在做的是为前男友写一个IF-Else语句 If Combo36.Value = "Contains" Then DoCmd.OpenForm "Test", , "", "[LastName] LIKE" + Contains + "", acNormal ElseIf Combo36.Value = "Is" Then DoCmd.OpenForm "Test", , "", "[LastName

我是新手,所以不要对我太苛刻。我现在做的是为前男友写一个IF-Else语句

    If Combo36.Value = "Contains" Then
            DoCmd.OpenForm "Test", , "", "[LastName] LIKE" + Contains + "", acNormal
    ElseIf Combo36.Value = "Is" Then
            DoCmd.OpenForm "Test", , "", "[LastName] =" + Matches + "", acNormal
    ElseIf Combo36.Value = "Begins With" Then
            DoCmd.OpenForm "Test", , "", "[LastName] LIKE" + BeginsWith + "", acNormal
    ElseIf Combo36.Value = "Ends With" Then
            DoCmd.OpenForm "Test", , "", "[LastName] LIKE" + EndsWith + "", acNormal
    ElseIf Combo36.Value = "Is Not" Then
            DoCmd.OpenForm "Test", , "", "[LastName] <>" + Matches + "", acNormal

但是就像我说的,我是新手,有没有更有效的方法呢?

好的,我找到了最好的方法,而不是写很多if语句。我为每个值字段创建了三个函数。在我的函数中

第一功能

Function valueInputFN(value As String) As String
If Forms![Searches]![Combo38] = "Is" Then
valueInputFN = ""

ElseIf Forms![Searches]![Combo38] = "Begins With" Then

ElseIf Forms![Searches]![Combo38] = "Contains" Then
valueInputFN = "*"

ElseIf Forms![Searches]![Combo38] = "Ends With" Then
valueInputFN = "*"
End If


End Function

 2nd Function
Function FirstNameFunc(Name1 As String) As String

If IsNull(Forms![Searches]![Text40].value) Then
 FirstNameFunc = "*"
 ElseIf Forms![Searches]![Text40].value = "" Then
 FirstNameFunc = "*"
Else
Forms![Searches]![Text40].SetFocus
 FirstNameFunc = Forms![Searches]![Text40].Text

 End If



End Function
3rd Function 
Function valueInput1FN(value As String) As String
If Forms![Searches]![Combo38] = "Is" Then
valueInput1FN = ""
End If
If Forms![Searches]![Combo38] = "Ends With" Then
valueInput1FN = ""
End If
If Forms![Searches]![Combo38] = "Contains" Then
valueInput1FN = "*"
End If
If Forms![Searches]![Combo38] = "Begins With" Then
valueInput1FN = "*"
End If    

End Function
上面是三个函数,下面是我在查询准则中的内容

Like valueInputFN("«value»") & FirstNameFunc("«Name1»") & valueInput1FN("«value»") Or "" Or Is Null
这很有魅力!现在,用户可以选择“是”、“以开始”、“包含”或“以结束”,并将检索正确的数据。我相信可能有更好的方法,但这对我来说非常有效

Like valueInputFN("«value»") & FirstNameFunc("«Name1»") & valueInput1FN("«value»") Or "" Or Is Null