简体   繁体   English

从查询中引用子表单

[英]Referring to a Subform from a Query

In MS Access 2010, I have a Query which quotes the following in the Criteria;在 MS Access 2010 中,我有一个查询,它在标准中引用了以下内容;

[Forms]![frm_Add_Item_Subform].[ActiveControl].[Caption]

This lets me use the "Caption" text of a Button within the query.这让我可以在查询中使用按钮的“标题”文本。 The following code is on the Button to capture the click.以下代码在 Button 上捕获点击。

Private Sub cmdClickMe_Click()
Debug.Print Me.cmdClickMe.Caption
Debug.Print Screen.ActiveControl.Caption
End Sub

I obtained information on how to do this at the following StackOverflow URL.我在以下 StackOverflow URL 中获得了有关如何执行此操作的信息。 use caption of pressed button from main form in query of other form 在其他表单的查询中使用主表单中按下按钮的标题

The functionality works ok when used in a Form.在表单中使用时,该功能可以正常工作。 But doesn't when its used within a Subform (which is where I need to use it).但是当它在子表单中使用时不会(这是我需要使用它的地方)。 I believe I need help tweaking the Query Criteria to refer to the Subform correctly.我相信我需要帮助调整查询条件以正确引用子表单。

Hoping someone will be able to give me some guidance on this.希望有人能在这方面给我一些指导。 Thanks in advance!提前致谢!

PS The main Form name is "frm_Add_Item_Main" PS主窗体名称为“frm_Add_Item_Main”

This is how to refer to subforms: 这是指代子窗体的方法:

Forms!mainFrm!subFormControlName.Form

so you need: 所以你需要:

Forms!mainFrm!subFormControlName.Form.ActiveControl.Caption

where subFormControlName is the name of the subform control (not the name of the subform) in the main form (it shows when the subform control is selected in the main form) 其中,subFormControlName是主窗体中子窗体控件的名称(不是子窗体的名称)(显示在主窗体中选择子窗体控件的时间)

This worked for me:这对我有用:

[Forms]![myMainForm]![mySubForm]![myComboBox] [表单]![myMainForm]![mySubForm]![myComboBox]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM