SubForm (Or SubReport) WHI AM I

A

AM

Hi

I a main form/report I have three subforms having source object same suppose
FRM_SUB. In main Form Form I name them Sub1 , Sub2, Sub3.

Subforms are unbound no child/master fields relation.

Now In subform code I want to know WHO AM I (sub1,sub2,sub3) so I can apply
different checks.

Filelds are same but sources are different depending on some calcs I cannot
do it in Main Form code its should be done in Subform

Interesting Situation Please Help

AM
 
D

Dirk Goldgar

Hi

I a main form/report I have three subforms having source object same
suppose FRM_SUB. In main Form Form I name them Sub1 , Sub2, Sub3.

Subforms are unbound no child/master fields relation.

Now In subform code I want to know WHO AM I (sub1,sub2,sub3) so I
can apply different checks.

Filelds are same but sources are different depending on some calcs I
cannot do it in Main Form code its should be done in Subform

Interesting Situation Please Help

AM

*If* the subform will have the focus on the main form at the time the
code is executed, then you can find out the name of the active control
on the main form, which will be the name of the subform control (Sub1,
Sub2, or Sub3), like this:

Dim strWhatSubform As String

strWhatSubform = Me.Parent.ActiveControl.Name

On the other hand, if you can't be sure the subform in question will
actually be the active control on the main form when the code runs, then
the best solution I can offer is to loop through the parent form's
controls until you find a subform control that contains the form object
whose code is running, like this:

Dim strWhatSubform As String
Dim ctl As Control

For Each ctl In Me.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is Me Then
strWhatSubform = ctl.Name
Exit For
End If
End If
Next ctl
 

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