vba 过滤 Microsoft Access 子表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17949586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Filtering Microsoft Access Subform
提问by Mike
I have a subform populated with different tasks. I want to filter them on DUE_DT
with a filter that happens automatically. Some of the records have a blank DUE_DT
, which I would like to filer out. I would also like to filter out records whose DUE_DT
is more than 30 days past. I tried using VB but I haven't been able to find the appropriate syntax.
我有一个填充了不同任务的子表单。我想DUE_DT
用自动发生的过滤器过滤它们。一些记录有空白DUE_DT
,我想将其归档。我还想过滤掉DUE_DT
过去 30 天以上的记录。我尝试使用 VB,但找不到合适的语法。
采纳答案by HansUp
"I want to filter them on DUE_DT with a filter that happens automatically."
“我想使用自动发生的过滤器在 DUE_DT 上过滤它们。”
I'm not quite sure what you have in mind there, but I wonder whether that could be handled by a WHERE
clause in the subform's record source query.
我不太确定您在那里有什么想法,但我想知道是否可以通过WHERE
子表单的记录源查询中的子句来处理。
WHERE DUE_DT >= Date() - 30
That would be automatic in the sense that the filter would always apply.
这将是自动的,因为过滤器将始终适用。
Note you don't have to add another condition to explicitly exclude Nulls (such as DUE_DT Is Not Null
) because Null is not >= Date() - 30
.
请注意,您不必添加另一个条件来明确排除 Null(例如DUE_DT Is Not Null
),因为 Null 不是>= Date() - 30
。
回答by Jonathan Elkins
Here is some syntax for appplying a filter to a sub form:
以下是将过滤器应用于子表单的一些语法:
Forms!MyMainForm.ASubFormOnMyMainForm.Form.Filter = "whatever your filter is"
Forms!MyMainForm.ASubFormOnMyMainForm.Form.FilterOn = True
回答by Fabio Pereira
Try this in VBA, should work on every form or module you put it in:
在 VBA 中试试这个,应该适用于你放入的每个表单或模块:
Form_subFormName.Filter = "DUE_DT IS NOT NULL AND DUE_DT >= #" & (Date - 30) & "#"
Form_subFormName.FilterOn = True
Replace the subFormName
in Form_subFormName
with the name of your subform, but keep the Form_
.
将subFormName
in替换为Form_subFormName
子表单的名称,但保留Form_
.