不幸的是,Access 没有该功能。你必须学习 VBA 才能实现这一点。
我认为分析过滤器会很困难。在我看来,为每个字段设置过滤器和默认值会更容易。需要实现打开表单的功能和一些公共的表单方法来设置值。
打开表单的函数如下所示:
Dim frm as Form_SomeForm
DoCmd.OpenForm "SomeForm", , , , , acHiden
Set frm = Forms("SomeForm")
frm.SetControlFilter("UserName", "=", "Foo")
frm.SetControlFilter("Age", "=", "123")
...
frm.ApplyFilter()
frm.Visible = True
表单模块“SomeForm”看起来像:
Dim m_stFiler as String
Public Sub SetControlFilter(ByVal stCtrl As String, ByVal stExp As String, ByVal stValue as String)
Dim ctl As Control
'-- set default value
set ctl = Me("stCtrl")
ctl.DefaultValue = "=""" & stValue & """"
'-- build filter
If m_stFiler <> "" Then m_stFiler = m_stFiler & " AND "
m_stFiler = m_stFiler & ctl.ControlSource & " " & stExp & " "" & stValue & "" "
End Sub
Public Sub ApplyFilter()
Me.Filter = m_stFiler
Me.FilterOn = True
End Sub