Using Set Control = Nested Subform

W

wrldruler

I've got a series of nested sub-forms:

(1a) Main Parent
(1b) Sub-form: Header of calendar -- Months, Days of Week, etc.
(1c) Continuous Sub-form: Displays employee vacations
From 1a (the Parent), I've been using the following syntax to assign a
control to Me and to a subform:

Set ctrl_Weekday = Me("WeekDay_Text_" & strNum)
Set ctrl_List = subfrm_Vacation_Details("List" & strNum)

But what is the syntax to Set the control to a NESTED subform.

I want to do something like:

Set ctrl_List =
subfrm_Vacations.subfrm_Vacation_Details("List" & strNum)

Thanks,

Chris
 
W

wrldruler

Never mind. This syntax did the trick:

Set ctrl_List = subfrm_Vacations!
subfrm_Vacation_Details("List" & strNum)

Thanks,

Chris
 
M

Marshall Barton

Newer versions of Access are more strict about the subform
object references. You should use the Form property:

Set ctrl_List =
subfrm_Vacations.FORM!subfrm_Vacation_Details.FORM("List" &
strNum)
 
W

wrldruler

Follow-up question:

I am moving my code to a Module so that it can be called from a
several forms, including a Popup.

I have 3 forms:

(1A) Main_Form
(1B) Sub_Form1
(1c) Nested_Subform2

I can go down to the Sub_Form1 level with this code.

Dim frm As Form
Set frm = Forms("Main_Form")

Dim sfr As SubForm
Set sfr = frm.Controls("Sub_Form1")

Dim ctrl_Combo_Units As Control
Set ctrl_Combo_Units = sfr("Field_Name")
Msgbox(ctrl_Combo_Units.Value)

But I can't figure out the syntax for the Nested.

I want to do something like:

Dim nested_sfr As SubForm
Set nested_sfr = frm.sfr.Controls("Nested_Subform2")

Dim ctrl_Combo_Units As Control
Set ctrl_Combo_Units = nested_sfr("Field_Name")
Msgbox(ctrl_Combo_Units.Value)


Thanks again,

Chris
 
M

Marshall Barton

wrldruler said:
Follow-up question:

I am moving my code to a Module so that it can be called from a
several forms, including a Popup.

I have 3 forms:

(1A) Main_Form
(1B) Sub_Form1
(1c) Nested_Subform2

I can go down to the Sub_Form1 level with this code.

Dim frm As Form
Set frm = Forms("Main_Form")

Dim sfr As SubForm
Set sfr = frm.Controls("Sub_Form1")

Dim ctrl_Combo_Units As Control
Set ctrl_Combo_Units = sfr("Field_Name")
Msgbox(ctrl_Combo_Units.Value)

But I can't figure out the syntax for the Nested.

I want to do something like:

Dim nested_sfr As SubForm
Set nested_sfr = frm.sfr.Controls("Nested_Subform2")

Dim ctrl_Combo_Units As Control
Set ctrl_Combo_Units = nested_sfr("Field_Name")
Msgbox(ctrl_Combo_Units.Value)


I think you might be confusing the subform control and the
form object it is displaying.

Try using some thing more like:

Dim frm As Form
Dim sfr As Form
Dim nested_sfr As Form
Set frm = Forms("Main_Form")
Set sfr = frm.Controls("Sub_Form1").Form
Set nested_sfr = sfr.Controls("Nested_Subform2").Form

Or, to get to nested directly from the main form:

Dim nested_sfr As Form
Set nested_sfr =
Forms!Main_Form.Sub_Form1.Form.Nested_Subform2.Form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top