简体   繁体   中英

Referring to a Subform from a Query

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!

PS The main Form name is "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)

This worked for me:

[Forms]![myMainForm]![mySubForm]![myComboBox]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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