简体   繁体   English

MS Access VBA - 使用日期过滤表单

[英]MS Access VBA - Filter form using Date

I am wrestling with a task to filter a form based on a date criteria.我正在努力处理基于日期条件过滤表单的任务。 I think I am munging the date format somehow and cannot find a combination that will return a result.我想我正在以某种方式修改日期格式并且找不到可以返回结果的组合。 There are valid dates on the subform;子表格上有有效日期; criteria should return a result - but returns ZERO records.标准应返回结果 - 但返回零记录。 I tried the DATE function as well as explicit #10/17/2017# type values.我尝试了 DATE 函数以及显式 #10/17/2017# 类型值。

Dim strFilter As String

Select Case Me!frmFilter.Value

    Case 1  'All
        Forms![InventoryList].[InventoryList subform].Form.FilterOn = False
    Case 2  'Active
        strFilter = "Forms![InventoryList].[InventoryList subform].Form.[StartDate] > #" & Date & "#"
        Forms![InventoryList].[InventoryList subform].Form.Filter = strFilter
        Forms![InventoryList].[InventoryList subform].Form.FilterOn = True
    Case 3  'Pending
        'do something else

End Select

End Sub

Any suggestions to help me move this task forward a little bit?有什么建议可以帮助我推进这项任务吗?

Thanks!谢谢!

This has to work if StartDate is a date and [InventoryList subform] is the name of the subform control :如果StartDate日期并且[InventoryList subform]是子表单控件的名称,这必须起作用:

Select Case Me!frmFilter.Value
    Case 1  'All
        Forms![InventoryList]![InventoryList subform].Form.FilterOn = False
    Case 2  'Active
        strFilter = "[StartDate] > Date()"
        Forms![InventoryList]![InventoryList subform].Form.Filter = strFilter
        Forms![InventoryList]![InventoryList subform].Form.FilterOn = True
    Case 3  'Pending
        'do something else
End Select

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM