[英]MS-ACCESS Filter Subform with Button
I am trying to do something I imagine is very trivial. 我正在尝试做一些我认为非常琐碎的事情。 I was able to do this using a ComboBox, but have switched to using SubForms, due to the ease of conditional formatting.
我能够使用ComboBox做到这一点,但是由于条件格式的易用性,我切换到了SubForms。
Form = Expiring 表格=即将到期
SubForm = CORE2 子表格= CORE2
Fields = [Core], [Active] 字段= [核心],[有效]
Button = CoreSearch 按钮= CoreSearch
Option Compare Database
Private Sub CoreSearch_Click()
Dim Task As String
Me.Refresh
Task = "SELECT * FROM CORE2.Expiring WHERE DateDiff('m', [Core RS], Date()) > 36 And [Active] = True"
DoCmd.ApplyFilter Task
End Sub
I keep getting The action of method is invalid because the form or report isn't bound to a table or query
. 我不断收到
The action of method is invalid because the form or report isn't bound to a table or query
。 Is this because I am not specifying where to apply the filter? 这是因为我没有指定在哪里应用过滤器?
I can't find any example that uses the FilterName argument, they all use the WHERE Condition argument. 我找不到任何使用FilterName参数的示例,它们都使用WHERE Condition参数。
ApplyFilter acts on whatever form the code is behind. ApplyFilter可以执行任何形式的代码。
Assuming button is on form CORE2. 假设按钮在表格CORE2上。
DoCmd.ApplyFilter , "DateDiff('m', [Core RS], Date()) > 36 And [Active] = True"
Alternatively: 或者:
Me.Filter = "DateDiff('m', [Core RS], Date()) > 36 And [Active] = True"
Me.FilterOn = True
Suggest naming subform/subreport container control different from the object it holds, such as ctrCore. 建议命名子窗体/子报表容器控件的名称与其所持有的对象不同,例如ctrCore。 If button is on main form and you want to apply filter to subform:
如果按钮位于主窗体上,并且您想将过滤器应用于子窗体:
Me.ctrCore.Form.Filter = "DateDiff('m', [Core RS], Date()) > 36 And [Active] = True"
Me.ctrCore.Form.FilterOn = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.