designspeaks
designspeaks

Reputation: 203

Calling a Control on a subform

I'm looking for a way to access a control on a subform, currently everything I have tried gives me an error of "cannot find".

my main form "frm_View" contains the subform "subform_View2"

subform_View2 contains a tab container

the tab container contains yet another subform "subform_View3" on the first tab

Separate form "frmAnswers"

I need to access a control on subform_View3 in order to insert information obtained from frmAnswers.

I've tried:

me.subform_view3!frm_View!control1
me.subform_view3!subform_view2!subform_View3!control1

Upvotes: 0

Views: 406

Answers (1)

Marek Stejskal
Marek Stejskal

Reputation: 2718

The thing is that you must treat the tab control as a special kind of container, with each page behaving similarly to another subform.

I have created an example, see picture below. enter image description here

The main form contains a TabControl (named tabControl) and the first page contains a subform (called SubForm) and that contains a text box (txb).

To get to the value of the text box you will need to path through the tab control like this:

Me.tabControl.Pages(0).Controls("SubForm")!txb.Value

or

Me.tabControl.Pages("Page1").Controls("SubForm")!txb.Value

or

Me.tabControl.Pages("Page1").Controls("SubForm").Controls("txb").Value

Notice that the SubForm is part of the "Controls" collection of the page, so you'll need to identify the tab control first, then the page (either by name or zero-based index) and then the subform itself to get to it's controls.

EDIT

If you want to call it from a form-independent code, you can target the form like this

Forms!MainForm!tabControl.Pages("Page1").Controls("SubForm")!txb.Value

Upvotes: 1

Related Questions