MS Access搜索按钮条件导致额外的运行时错误3075

时间:2018-12-19 13:10:01

标签: ms-access

我有一个搜索按钮,可以搜索各个字段,效果很好,但是当我第一次打开表单并尝试搜索时,我会额外收到3075的运行时错误,但是一旦我清除了过滤器,搜索条件就可以正常工作。我应该在下面的代码中解决什么? SUb类别和阶段是文本

Private Sub cmdfilter_Click()
  Dim strWhere As String
  Dim lngLen As Long

  If Not IsNull(Me.AgencyDropDown) Then
        strWhere = strWhere & "([Agency] = " & Me.AgencyDropDown & ") AND "

End If

 If Not IsNull(Me.Itcleaddropdown) Then
        strWhere = strWhere & "([ITC Lead] = " & Me.Itcleaddropdown & ") AND "

End If


  If Not IsNull(Me.SubcatDropdown) Then
        strWhere = strWhere & "([Subcategory] = """ & Me.SubcatDropdown & """) AND "

End If

  If Not IsNull(Me.StageDrpdown) Then
        strWhere = strWhere & "([Stage] = """ & Me.StageDrpdown & """) AND "

End If

If Not IsNull(Me.ContractVehicleDropDown) Then
        strWhere = strWhere & "([Contract Vehicle] = " & Me.ContractVehicleDropDown & ") AND "

End If

  If Not IsNull(Me.FYdropdown) Then
        strWhere = strWhere & "([New FY] = " & Me.FYdropdown & ") AND "

End If

 If Not IsNull(Me.Searchdropdown) Then
        strWhere = strWhere & "([Opportunity Name] Like ""*" & Me.Searchdropdown & "*"") AND "

End If

 If Not IsNull(Me.SearchScopedropdown) Then
        strWhere = strWhere & "([Opportunity Scope] Like ""*" & Me.SearchScopedropdown & "*"") AND "

End If


 lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
    MsgBox "No criteria", vbInformation, "Nothing to do."
    Else
    strWhere = Left$(strWhere, lngLen)



        Me.filter = strWhere
        Me.FilterOn = True

pic of the error

1 个答案:

答案 0 :(得分:0)

我怀疑打开表单后您的下拉列表值为NULL。

在查询中,使用NZ()函数用以下任意一种替换所有可能的NULL:

  • 空字符串:nz(dropdown.value,"")
  • 数字的0:nz(dropdown.value,0)

示例:

  If Not IsNull(Me.SubcatDropdown) Then
        strWhere = strWhere & "([Subcategory] = """ & nz(Me.SubcatDropdown,"") & """) AND "