469,267 Members | 887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Get Name Of Subform Control

When I click on a control in a subform, what is the syntax to return the
name of the subform control on the main form that contains the subform?

MsgBox "MySubform is in " & < ???? >

Thanks,

Sally
Nov 13 '05 #1
10 17997
On Sat, 15 Jan 2005 20:18:05 GMT, "Sally" <sm*****@notmyemail.com>
wrote:

mysubformcontrol.Form!mycontrol

mysubformcontrol is the name of the subform control on the parent
form.
With .Form you step into the subform.
mycontrol is the name of the control in the subform.

-Tom.

When I click on a control in a subform, what is the syntax to return the
name of the subform control on the main form that contains the subform?

MsgBox "MySubform is in " & < ???? >

Thanks,

Sally


Nov 13 '05 #2
Sally wrote:
When I click on a control in a subform, what is the syntax to return
the name of the subform control on the main form that contains the
subform?

MsgBox "MySubform is in " & < ???? >


A handy reference for this can be found at
http://www.mvps.org/access/forms/frm0031.htm

--
Joan Wild
Microsoft Access MVP
Nov 13 '05 #3
Hi Sally

Because you are clicking on a control in the subform, you can guarantee that
the subform has the focus, and therefore its container control is the active
control on the main form. Therefore, you can get it like this:
Me.Parent.ActiveControl.Name
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Sally" <sm*****@notmyemail.com> wrote in message
news:1U*****************@newsread3.news.pas.earthl ink.net...
When I click on a control in a subform, what is the syntax to return the
name of the subform control on the main form that contains the subform?

MsgBox "MySubform is in " & < ???? >

Thanks,

Sally

Nov 13 '05 #4
Joan,

Thank you for responding! I want to get the name of the subform control on
the main form. Don't see anything for that at your URL.

Sally
"Joan Wild" <jw***@nospamtyenet.com> wrote in message
news:ez*************@tk2msftngp13.phx.gbl...
Sally wrote:
When I click on a control in a subform, what is the syntax to return
the name of the subform control on the main form that contains the
subform?

MsgBox "MySubform is in " & < ???? >


A handy reference for this can be found at
http://www.mvps.org/access/forms/frm0031.htm

--
Joan Wild
Microsoft Access MVP

Nov 13 '05 #5
Thank you for responding! I'm looking for code that returns
"mysubformcontrol".

Sally

"Tom van Stiphout" <no*************@cox.net> wrote in message
news:os********************************@4ax.com...
On Sat, 15 Jan 2005 20:18:05 GMT, "Sally" <sm*****@notmyemail.com>
wrote:

mysubformcontrol.Form!mycontrol

mysubformcontrol is the name of the subform control on the parent
form.
With .Form you step into the subform.
mycontrol is the name of the control in the subform.

-Tom.

When I click on a control in a subform, what is the syntax to return the
name of the subform control on the main form that contains the subform?

MsgBox "MySubform is in " & < ???? >

Thanks,

Sally

Nov 13 '05 #6
Graham,

Thanks for responding! That looks just like what I am looking for.
Appreciate it.

Sally
"Graham Mandeno" <Gr************@nomail.please> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
Hi Sally

Because you are clicking on a control in the subform, you can guarantee that the subform has the focus, and therefore its container control is the active control on the main form. Therefore, you can get it like this:
Me.Parent.ActiveControl.Name
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Sally" <sm*****@notmyemail.com> wrote in message
news:1U*****************@newsread3.news.pas.earthl ink.net...
When I click on a control in a subform, what is the syntax to return the
name of the subform control on the main form that contains the subform?

MsgBox "MySubform is in " & < ???? >

Thanks,

Sally


Nov 13 '05 #7

"Sally" <sm*****@notmyemail.com> wrote
Thanks for responding! That looks just
like what I am looking for.


Even simpler, for code executing in the module of the Form embedded in the
Subform Control... because the Subform has focus, Me.Name will return its
name.

Nov 13 '05 #8
On Sun, 16 Jan 2005 03:12:39 GMT, "Larry Linson" <bo*****@localhost.not>
wrote:

"Sally" <sm*****@notmyemail.com> wrote
Thanks for responding! That looks just
like what I am looking for.


Even simpler, for code executing in the module of the Form embedded in the
Subform Control... because the Subform has focus, Me.Name will return its
name.


Actually, Me is the name of the object containing the code that is running and
has nothing to do with the Active Control. "Me" will, however, always return
a reference to the subform object. It will not return a reference to the
suform control that -contains- that form.

It is possible to incontrovertibly determine the subform control on the parent
form that contains a given subform if you have a reference to the subform, and
it doesn't depend on active controls, etc. The way you do it is to cycle
through all the controls on the parent form, and for each subform control
found, compare the subform's .Form.Hwnd property to the original subform's
..Hwnd property. If 2 form references have the same .Hwnd property value, the
references are to the same form instance.
Nov 13 '05 #9
Hi Sally,

I think you'll have to iterate the control collection for the form testing
each control for TypeOf. When you find a subform get its name. From Acc97
Help:

Use If TypeOf construct to determine whether the Control passed into a
procedure is a text box.

Sub ControlProcessor(MyControl As Control)
If TypeOf MyControl Is CommandButton Then
Debug.Print "You passed in a " & TypeName(MyControl)
ElseIf TypeOf MyControl Is CheckBox Then
Debug.Print "You passed in a " & TypeName(MyControl)
ElseIf TypeOf MyControl Is TextBox Then
Debug.Print "You passed in a " & TypeName(MyControl)
End If
End Sub

HTH
--
-Larry-
--

"Sally" <sm*****@notmyemail.com> wrote in message
news:7Q****************@newsread1.news.pas.earthli nk.net...
Joan,

Thank you for responding! I want to get the name of the subform control on
the main form. Don't see anything for that at your URL.

Sally
"Joan Wild" <jw***@nospamtyenet.com> wrote in message
news:ez*************@tk2msftngp13.phx.gbl...
Sally wrote:
When I click on a control in a subform, what is the syntax to return
the name of the subform control on the main form that contains the
subform?

MsgBox "MySubform is in " & < ???? >


A handy reference for this can be found at
http://www.mvps.org/access/forms/frm0031.htm

--
Joan Wild
Microsoft Access MVP


Nov 13 '05 #10
Sally wrote:
Graham,

Thanks for responding! That looks just like what I am looking for.
Appreciate it.

Sally


I put this in the OnCurrent event of the subform.
MsgBox "Control Name is " & Me.ActiveControl.Name
MsgBox "Parent is " & Me.Parent.Name
MsgBox "Me is " & Me.Name
Nov 13 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Melissa | last post: by
2 posts views Thread by maxjake via AccessMonster.com | last post: by
6 posts views Thread by DMUM via AccessMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.