Referring to a Subform from a Query
Asked Answered
D

2

1

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"

Dimmick answered 28/4, 2016 at 3:12 Comment(0)
I
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)

Indefinite answered 28/4, 2016 at 23:58 Comment(1)
Perfect, thank you! This was the code that worked (as you suggested)! .... [Forms]![frm_Add_Item_Main]![NavigationSubform].[Form].[ActiveControl].[Caption]Dimmick
D
0

This worked for me :

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

Drilling answered 3/9, 2022 at 17:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.