Ms access vba访问查询错误

Ms access vba访问查询错误,ms-access,vba,Ms Access,Vba,当我尝试通过多个字段进行筛选时,出现3075运行时错误。这是我的密码: Private Sub Search_Click() Dim strWhere As String Dim i As Variant Dim varItem As Variant Dim strDelim As String If Nz(Me.txtFullName, "") <> "" Then strWhere = strWhere & "FullName Like '*" & R

当我尝试通过多个字段进行筛选时,出现3075运行时错误。这是我的密码:

Private Sub Search_Click()
Dim strWhere As String
Dim i As Variant
Dim varItem As Variant
Dim strDelim As String


If Nz(Me.txtFullName, "") <> "" Then
    strWhere = strWhere & "FullName Like '*" & Replace(Me.txtFullName, "'", "''") & "*' AND "
End If

If Nz(Me.txtCivil, "") <> "" Then
    strWhere = strWhere & "CivilService_Status Like '*" & Replace(Me.txtCivil, "'", "''") & "*' AND "
End If

If Nz(Me.txtOffice, "") <> "" Then
    strWhere = strWhere & "Office_Title Like '*" & Replace(Me.txtOffice, "'", "''") & "*' AND "
End If

'If Nz(Me.cboDegree, "") <> "" Then
    'strWhere = strWhere & "[UpdatedBy] = '" & Me.cboDegree.Value & "' AND "
'End If

For Each i In Me.lstPosition.ItemsSelected
    strWhere = strWhere & strDelim & "Bureau='" & Me.lstPosition.ItemData(i) & strDelim & "' AND "
Next i

If Nz(Me.txtStartdate, "") <> "" Then 'from ,to salary range Dates
   strWhere = strWhere & "AgencyStart_Date BETWEEN #" & Me.txtStartdate & "# AND #" & Me.txtTodate & "# 'AND"
End If

'If Nz(Me.txtStartdate, "") <> "" Then 'from ,to salary range Dates
   ' strWhere = strWhere & "Request_Date BETWEEN #" & Me.txtStartdate & "# AND #" & Me.txtTo & "# 'AND"
'End If


For Each i In Me.lstBureau.ItemsSelected 'listbox
'If Not IsNull(i) Then
    strWhere = strWhere & strDelim & "Bureau='" & Me.lstBureau.ItemData(i) & strDelim & "' AND "
Next i
'End If

If Nz(Me.txtdivision, "") <> "" Then
    strWhere = strWhere & "Division Like '*" & Replace(Me.txtdivision, "'", "''") & "*' AND "
End If


For Each i In Me.lstFund.ItemsSelected 'listbox
   'If Not IsNull(i) Then
    strWhere = strWhere & strDelim & "Fund='" & Me.lstFund.ItemData(i) &        

 1. List item

strDelim & "' AND "
    'End If
Next i
    If Nz(Me.txtSalaryfrom, "") <> "" Then 'from ,to salary range Dates
     strWhere = strWhere & "SumOfAnnualized_Salary BETWEEN #" &       Me.txtSalaryfrom   
    & "# AND #" & Me.txtSalaryto & "# 'AND"
    End If




    If strWhere <> "" Then
    strWhere = Left(strWhere, Len(strWhere) - 5) 'Remove the extra AND
    Report_Onboard_summary.Filter = strWhere
    Report_Onboard_summary.FilterOn = True
   DoCmd.OpenReport "Onboard_summary", acViewPreview, WhereCondition:=strWhere
   Else
    Report_Onboard_summary.Filter = ""
   Report_Onboard_summary.FilterOn = False
    End If



End Sub

这个现在突然出现了。我能够修复语法错误,但现在当报告弹出时,字段为空

@HansUp我在删除尾随后立即添加了它,并将where显示为Debug。在此处打印strWhere,如果没有发现问题,则将该字符串粘贴到上面的{}中。当我认为需要的是B=this或B=that时,调查局看起来很可疑,因为它试图将B=this和B=that串起来。StartDate也有一个可能不需要的尾随单引号。@donPablo我是vba新手,你想让我从即时窗口中删除AND吗?亲爱的@Tyrone,请解释一下
1。列表项
表示代码行之间的内容。
CivilService_Title Like '*Scientist*' AND Bureau='Part Time' AND AgencyStart_Date BETWEEN #8/22/2010# AND #12/23/2017#  AND [Fund] = 'CTL' AND SumOfAnnualized_Salary BETWEEN' 65000' AND '100000 '