[在MS Access 2019 Professional Plus 2019中工作。但这并不重要。] 我的设置可以缩小到这个层次结构,它本身工作得非常好 。
'------> Hierarchy of objects :
"myMainForm" contains :
"select_client" (ComboBox based on "client" table)
"select_status" (ComboBox based on "status" table)
' and some multi-select checkboxes that forbid use of Master/Child feature
"mySubForm"
"Source Object" : "myQuery" ' "mySubForm" not saved with an explicit name, local to "myMainForm"
"mQuery" filters the table "course" :
"client_ID" criteria : [Forms]![myMainForm]![select_client]
"status_ID" criteria : [Forms]![myMainForm]![select_status]
'------> "myMainForm" VBA to requery on change (could be performed with Macros) :
Private Sub select_client_Change()
Me!mySubForm.Requery
End Sub
Private Sub select_status_Change()
Me!mySubForm.Requery
End Sub
然后,我尝试将 "myMainForm "嵌入到一个更高级别的表单中(比方说 "myNavForm") 。
"myNavForm" contains :
"myMainForm" contains :
' same as above from there
"mySubForm"
当我试着运行 "myMainForm "时 "myNavForm"
,我得到的提示是 [Forms]![myMainForm]![select_client]
和 [Forms]![myMainForm]![select_status]
和 "myMainForm"
完全停止工作。
我最初以为问题是与组合框的值尚未加载有关,当 "myQuery"
触发,所以我在下面的VBA中加入了 "myMainForm"
:
Private Sub Form_Load()
Me!mySubForm.SourceObject = "Query.myQuery"
Me!mySubForm.Requery
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me!mySubForm.SourceObject = ""
End Sub
但问题还是一样。我想这是我的一个范围路径错误造成的,但我想不通。我尝试了绝对路径 "myQuery"
如上图所示。我也试过使用相对路径与 .Parent
不成 "myMainForm"
的工作(甚至不需要嵌入在 "myNavForm"
).
因此,我被卡住了,我很绝望,我想要回我的NodeMongoDB环境,但我必须在Access中做这件事(不要问!)。
任何想法如何使它与嵌入工作?尽可能地,我宁愿坚持这种设置,避免输入更复杂的VBA(语法让我头疼),但如果需要的话,我愿意接受;-)
谢谢任何形式的帮助,让我从这个噩梦中解脱出来 !
[EDIT : SOLUTION IN MY USE CASE BASED ON ACCEPTED ANSWER (for future readers !)] 。
感谢@Olivier , 这里是解决方案工作完美无瑕 :
'------> Hierarchy of objects :
"myMainForm" contains :
"select_client" '(ComboBox based on "client" table)
"select_status" '(ComboBox based on "status" table)
"mySubForm"
"Source Object" : "myQuery" 'remove all criteria from the query !
' ------> Handle the rest in VBA :
'Lets write this only once...
Private Sub updateResult()
mySubForm.Form.Filter = "client_ID=" & select_client & " AND status_ID=" & select_status
mySubForm.Form.FilterOn = True
End Sub
'Apply filter with default values upon loading
Private Sub mySubForm_Current()
updateResult
End Sub
'Update filter whenever a control is updated
Private Sub select_client_AfterUpdate()
updateResult
End Sub
Private Sub select_status_AfterUpdate()
updateResult
End Sub
总而言之,我终于有了一个很好的框架,可以在任何控件更新后,在飞行中更新任何多标准查询,并在表单上立即查看结果,就像任何现代GUI应该做的那样。再次感谢Olivier !
这是因为,那么你的 select_client
有另一条路。现在是
[Forms]![myNavForm]![myMainForm].Form![select_status]
哪儿 myMainForm
现在是一个子表单控件。它的名称可能与包含的表单不同。
与其在查询中包含这样的路径,不如尝试像这样过滤子表单。
mySubForm.Form.Filter = "client_ID=" & select_client & " AND status_ID=" & select_status
mySubForm.Form.FilterOn = True
你可以在这两个字段的更新后事件和表单的OnCurrent事件中这样做。