是否可以过滤引用子表单的控件?

时间:2015-05-01 02:56:02

标签: vba ms-access filter controls subform

这是我所指的代码:

Dim ctl as Control
For Each ctl In Me.Form
  If ctl.ControlType = acSubform
    ctl.Filter = "[StartDate] <= [Date] and [EndDate] >= [Date]"
    ctl.FilterOn = True
  End If
Next ctl

显然这不起作用(并且它与过滤器字符串无效无关)。我猜我不能在控件对象上使用Filter方法。但有没有办法解决这个问题?也许创建一个SubForm变量,然后以某种方式将它分配给Control所指的对象?救命!谢谢!

1 个答案:

答案 0 :(得分:2)

没有多大意义。您既不能也不会对所有控件应用过滤器。

这是你可能想到的:

With Me!NameOfYourSubformControl.Form
    .Filter = "[StartDate] <= [Date] and [EndDate] >= [Date]"
    .FilterOn = True
End With

那就是:

Dim ctl as Control
For Each ctl In Me.Form
  If ctl.ControlType = acSubform
    ctl.Form.Filter = "[StartDate] <= [Date] and [EndDate] >= [Date]"
    ctl.Form.FilterOn = True
  End If
Next ctl