[AccessD] Acquiring subform's subform object name

Charlotte Foust cfoust at infostatsystems.com
Mon Mar 20 11:33:32 CST 2006


The sourceobject is a pointer to an object viewed in the control.  Tab
controls aren't containers in the same sense as are forms and subforms
so they always get ignored.  How you acquire the name depends on where
you do it from.  The subform itself always knows who it is, but the
parent doesn't need to know as long as the sourceobject is set, and it
doesn't necessarily have to be set to the same sourceobject all the
time.  From the parent form you should always be able to use
Me.subformcontrol.Form.name to get the name of the subform object
itself, once you know that a sourceobject exists. 


Charlotte Foust

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Erbach
Sent: Saturday, March 18, 2006 3:25 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Acquiring subform's subform object name

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
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list