SubForm

W

warrio

Hi there,

In the case that a form/report contains many instances of a same form/report
as a subform/subreport,
is there a way for a subform or a subreport to know which one it is compared
to the main form?
in other words, how can the child know who is he compared to his/her
brothers.. am I subForm1, SubForm2 or SubForm3??

Thanks for any suggestion :)
 
D

Dirk Goldgar

warrio said:
Hi there,

In the case that a form/report contains many instances of a same
form/report as a subform/subreport,
is there a way for a subform or a subreport to know which one it is
compared to the main form?
in other words, how can the child know who is he compared to his/her
brothers.. am I subForm1, SubForm2 or SubForm3??

Thanks for any suggestion :)


If the subform is currently active -- has the parent form's focus -- then
code on the subform should be able to test by way of the parent's
ActiveControl:

'------ start of example code #1 ------
Dim ctl As Control

With Me.Parent.ActiveControl
If .ControlType = acSubform Then
If .Form Is Me Then
MsgBox "I'm in the control named " & .Name & "!"
End If
End If
End With
'------ end of example code #1 ------

If the subform may not have the focus when the code is executed, I believe
you'd have to loop through the parent form's controls:

'------ start of example code #2 ------
Dim ctl As Control

For Each ctl In Me.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is Me Then
MsgBox "I'm in the control named " & ctl.Name & "!"
Exit For
End If
End If
Next ctl
'------ end of example code #2 ------
 
M

Marshall Barton

warrio said:
In the case that a form/report contains many instances of a same form/report
as a subform/subreport,
is there a way for a subform or a subreport to know which one it is compared
to the main form?
in other words, how can the child know who is he compared to his/her
brothers.. am I subForm1, SubForm2 or SubForm3??


I think you can use:

Parent.ActiveControl.Name
 
W

warrio

Great!! thanks a lot for the your quick response and the code sample
Have a nice evening
 

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