【问题标题】:DoCmd.AppltFilter with multiple criteria overwriting覆盖多个条件的 DoCmd.AppltFilter
【发布时间】:2020-09-28 13:19:40
【问题描述】:

我有一个带有 2 个过滤器的 MS.Access 表单,一个使用文本框在日期之间进行过滤

DoCmd.ApplyFilter , "[Start Date] Between #" & Format([AVstrtdt], "yyyy\/mm\/dd") & "# And #" & Format([AVEnDt], "yyyy\/mm\/dd") & "#"

其他过滤器使用组合框按部门..

DoCmd.ApplyFilter "", "[OpDescription]=" & ([CmbBxDepart]) & ""

两者都可以完美地单独工作,但它们会相互覆盖 IE 日期范围会覆盖部门过滤器或部门过滤器会覆盖日期过滤器,因此我一直在尝试使用 Or 函数将它们作为一个过滤器粘在一起

但不断收到类型不匹配错误...

Private Sub ApplyDtFilt_Click()

DoCmd.ApplyFilter , "[Start Date] Between #" & Format([AVstrtdt], "yyyy\/mm\/dd") & "# And #" & Format([AVEnDt], "yyyy\/mm\/dd") & "#" Or "", "[OpDescription]=" & ([CmbBxDepart]) & ""

End Sub

我已经搜索并找到了类似的帖子,但我似乎找不到问题所在...有什么想法吗? 在我看来还不错..

谢谢..

【问题讨论】:

    标签: vba ms-access filter


    【解决方案1】:

    使用一个表达式 - 作为 SQL 中的 WHERE 子句:

    DoCmd.ApplyFilter , "([Start Date] Between #" & Format([AVstrtdt], "yyyy\/mm\/dd") & "# And #" & Format([AVEnDt], "yyyy\/mm\/dd") & "#) Or ([OpDescription]=" & [CmbBxDepart] & ")"
    

    或者,设置表单的Filter属性:

    Dim Filter As String
    
    Filter = "([Start Date] Between #" & Format([AVstrtdt], "yyyy\/mm\/dd") & "# And #" & Format([AVEnDt], "yyyy\/mm\/dd") & "#) Or ([OpDescription]=" & [CmbBxDepart] & ")"
    Me.Filter = Filter
    Me.FilterOn = True
    

    【讨论】:

    • Hi Gustav.. 它修复了类型不匹配错误,但过滤器都不适用...
    • 尝试设置过滤器属性。请查看扩展答案。
    • 感谢 Gustav,这已经奏效了,替代解决方案显示两组数据完全没有被两个标准过滤,只需将 Or 交换为 And got it 非常感谢...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 2010-10-15
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    相关资源
    最近更新 更多