Access 2003: Finding a parent subform control

Y

Yarik

Hi,

Let's say I have a form (F1) that has a subform control (SFC), which
in turn displays some other form (F2). The question is: if I have a
variable referring to an instance of F2 (i.t. an instance of the
subform), how exactly can I obtain a reference to the instance of the
subform control that "hosts" the given instance of F2?

I thought it would be easy, like using Parent property for the
subform. But the Parent property contains a reference to the parent
form, not to the parent subform control. Does anybody know how to do
what I want?

Thank you,
Yarik.
 
D

Dirk Goldgar

Yarik said:
Hi,

Let's say I have a form (F1) that has a subform control (SFC), which
in turn displays some other form (F2). The question is: if I have a
variable referring to an instance of F2 (i.t. an instance of the
subform), how exactly can I obtain a reference to the instance of the
subform control that "hosts" the given instance of F2?

I thought it would be easy, like using Parent property for the
subform. But the Parent property contains a reference to the parent
form, not to the parent subform control. Does anybody know how to do
what I want?


The hosting control will be the subform control on the parent form whose
form object is the same object as the subform instance. So you could run
code along these lines:

Dim sf As Form

' ... somewhere in here, sf is set to a reference to the subform.

Dim ctl As Control

For Each ctl In sf.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is sf Then
MsgBox "I'm in the control named " & ctl.Name & "!"
Exit For
End If
End If
Next ctl
 
Y

Yarik

The hosting control will be the subform control on the parent form whose
form object is the same object as the subform instance.  So you could run
code along these lines:

    Dim sf As Form
....

Thanks Dirk! That's exactly what I needed.

(After enocuntering all the troubles involved into using "Is" with
controls, I had some doubts about using "Is" here, with forms. But it
looks like my doubts were ungrounded - the code you provided works
just fine.)
 

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