Referring to a Subform from a Query

北城余情 提交于 2019-12-31 07:16:11

问题


In MS Access 2010, I have a Query which quotes the following in the Criteria;

[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.

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. 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!

P.S. The main Form name is "frm_Add_Item_Main"


回答1:


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)



来源:https://stackoverflow.com/questions/36904595/referring-to-a-subform-from-a-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!