Get Name Of Subform Control

  • Thread starter Thread starter Sally
  • Start date Start date
S

Sally

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
 
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
 
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
 
Graham,

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

Sally


Graham Mandeno said:
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 said:
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
 
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
 
Sally said:
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
 
Back
Top