我创建了一个表格,员工可以在其中按姓名或ID搜索客户。我正在尝试添加还可以选择带有“客户类型/机会类型”复选框的功能,以进一步过滤搜索结果。我收到运行时错误3075,感谢您的帮助。

Private Sub btnSearch_Click()

'Code to show results based on keyword entered and checkbox selected

    Dim strSearch As String
    Dim strText As String
    Dim NewBuild As String
    Dim Winback As String
    Dim Renewal As String

    If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
    MsgBox "You must enter a Name or ID to search!", vbOKOnly, "Keyword Needed"
    Me.txtSearch.SetFocus

    Else

    If Me.chkNewBuild = True Then
        NewBuild = "New Build"
    End If

    If Me.chkWinback = True Then
        Winback = "Winback"
    End If

    If Me.chkRenewal = True Then
        Renewal = "Renewal"
    End If

    strText = txtSearch.Value
    strSearch = "SELECT * FROM qryPropertiesALL " _
    & "WHERE ((([OpportunityType] = " _
    & NewBuild & ")or ([OpportunityType] = " _
    & Winback & ") or ([OpportunityType] = " _
    & Renewal & ") AND (PropertyName like ""*" & strText & "*"") or (Property_ID like ""*" & strText & "*"")))"
    Me.RecordSource = strSearch


    End If

End Sub

最佳答案

尝试这个:

Private Sub btnSearch_Click()

'Code to show results based on keyword entered and checkbox selected

    Dim strSearch As String
    Dim strText As String
    Dim NewBuild As String
    Dim Winback As String
    Dim Renewal As String

    If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
    MsgBox "You must enter a Name or ID to search!", vbOKOnly, "Keyword Needed"
    Me.txtSearch.SetFocus

    Else

    If Me.chkNewBuild = True Then
        NewBuild = "New Build"
    End If

    If Me.chkWinback = True Then
        Winback = "Winback"
    End If

    If Me.chkRenewal = True Then
        Renewal = "Renewal"
    End If

    strText = txtSearch.Value
    strSearch = "SELECT * FROM qryPropertiesALL " _
    & "WHERE OpportunityType = '" _
    & NewBuild & "' or OpportunityType = '" _
    & Winback & "' or OpportunityType = '" _
    & Renewal & "' AND PropertyName like '" & strText & "' or Property_ID like '" & strText & "'"

    Me.RecordSource = strSearch

    End If

End Sub

关于ms-access - 如何更新此代码,而不会出现运行时错误3075?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41685676/

10-12 01:57