如何更新此代码而不是运行时错误3075?

时间:2017-01-16 21:58:08

标签: ms-access error-handling access-vba runtime

我创建了一个表单,员工可以通过名称或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

1 个答案:

答案 0 :(得分:1)

试试这个:

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