Form / Query对一旦嵌入到另一个Form中就停止工作

问题描述 投票:0回答:1

[[在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"

[当我尝试运行"myNavForm"时,提示输入[Forms]![myMainForm]![select_client][Forms]![myMainForm]![select_status],并且"myMainForm"完全停止工作。

我首先认为问题与触发"myQuery"时尚未加载ComboBox值有关,所以我在"myMainForm"中添加了以下VBA:

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"中)。

因此,我陷入了束手无策的绝望之中,我希望返回Node / MongoDB环境,但是我必须在Access中执行此操作(不要问!)。

任何想法如何使其能够嵌入?我尽可能地坚持该设置,避免输入更复杂的VBA(语法让我头疼),但是如果需要的话,我也乐于接受;-)

感谢您提供任何帮助,以使我摆脱噩梦!


[[编辑:基于使用的答案的我的使用案例解决方案(供将来的读者使用!]

感谢@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一样,立即在表单上查看结果!再次感谢奥利维尔!

[[正在使用MS Access 2019 Professional Plus2019。虽然没关系。]我的设置可以缩小到此层次结构,它本身可以很好地工作:'------> ...的层次结构...

vba ms-access ms-access-2016
1个回答
2
投票

这是因为您的select_client具有另一条路径。现在是

© www.soinside.com 2019 - 2024. All rights reserved.