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.
Form = Expiring
SubForm = CORE2
Fields = [Core], [Active]
Button = 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
. 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.
ApplyFilter acts on whatever form the code is behind.
Assuming button is on form 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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.