[AccessD] Acquiring subform's subform object name

Steve Erbach erbachs at gmail.com
Sat Mar 18 17:24:43 CST 2006


Shamil,

Interesting.  When I was experimenting with this I was flabbergasted
that a subform control's SourceObject could not directly tell the name
of its subform control.  In my case the Me.Parent.Name skipped right
past the Subform, the Page, and the Tab controls to the main Form as
if those three intervening "containers" weren't even there.

Your code does the trick but it sure looks like a game of Blind Man's
Bluff to me.

Thank you very much for taking time to help me, Shamil.

Steve Erbach
Neenah, WI
http://TheTownCrank.blogspot.com


On 3/18/06, Shamil Salakhetdinov <shamil at users.mns.ru> wrote:
> Steve,
>
> Here is the code to call from subform:
>
> Dim ectl As Access.Control
> Dim fsub As Access.SubForm
>     For Each ectl In Me.Parent.Controls
>       If ectl.ControlType = acSubform Then
>          Set fsub = ectl
>          If Len(fsub.SourceObject) > 0 Then
>              If Not fsub.Form Is Nothing Then
>                 If fsub.Form Is Me.Form Then
>                    MsgBox "My subform control name is " & fsub.Name, _
>                            vbInformation + vbOKOnly
>                 End If
>              End If
>          End If
>       End If
>     Next ectl
>
> Be careful with calling this code from subform's Open or Load event,
> especially in the case when on main form there are several subform controls
> using the same form....
>
> HTH,
> Shamil
>
> ----- Original Message -----
> From: "Steve Erbach" <erbachs at gmail.com>
> To: "Access Developers discussion and problem solving"
> <accessd at databaseadvisors.com>
> Sent: Saturday, March 18, 2006 4:52 PM
> Subject: [AccessD] Acquiring subform's subform object name
>
>
> > Dear Group,
> >
> > I have a form, frmMainMenu, that contains a Tab Control.  The 8 tabs
> > in the Tab Control are generically named Tab1, Tab2, etc.
> >
> > Each of the Tabs has one Subform Control "embedded" in it; each
> > Subform is also generically named:  Subform1, Subform2, etc.  The
> > reason for this is that frmMainMenu is set up with another Subform
> > Control "outside" the Tab Control.  This subform acts like the
> > vertical menu in an Access database window.  Once a menu item is
> > clicked, then all the tabs change, sometimes fewer tabs visible,
> > sometimes more, depending on which vertical menu item is selected.
> >
> > Anyway my problem is this:
> >
> > Say that Tab3's subform control, Subform3, has the form frmCustomers
> > as the subform's Source Object.  From the code within frmCustomers I
> > would like to be able to determine the name of it's subform control
> > "container".
> >
> > Me.Parent.Name gives me the name of the "master" form, frmMainMenu.
> > I've tried all sorts of things short of enumerating the collection of
> > controls to simply find the name of the subform control that
> > "contains" frmCustomers.
> >
> > Could you give me an idea?
> >
> > Regards,
> >
> > Steve Erbach



More information about the AccessD mailing list