Return Name Of Subform Control

  • Thread starter Thread starter Melissa
  • Start date Start date
M

Melissa

I have forty-two small subforms on a form. I need help with the code that
will return the name of the subform control when I click on any subform
control. I know how to select all the subform controls at once and then
enter =MyFunction in the Enter event; I need the code for MyFunction.

Thanks,

Melissa
 
Melissa said:
I have forty-two small subforms on a form. I need help with the code
that will return the name of the subform control when I click on any
subform control. I know how to select all the subform controls at
once and then enter =MyFunction in the Enter event; I need the code
for MyFunction.

I believe that in the subform control's Enter event,

Me.ActiveControl.Name

will give you the name of the subform control.
 
uI am not absolutely certain I understand what you are asking. However, some
general rules:

A form can always reference it's own controls by Me.controlName. A control
can always reference its own enter code by controlname_enter or you can
create your own sub or function in the fomr's code page and then put =subname
in the control's event criteria using the properties page window (easiest
way).

In either case, depending on where you are referencing from all objects
located on a form can be referenced by:

Forms!formname1!subform1!subform2.controlname.property

If you are referencing a control on the current form this can be shortened
to Me.controlname.property

If you are at the form level and have a subform with the control it can be
shortened to Me.subformname.controlname.property.

etc. But the idea always remains the same. Remeber, for most controls the
default property is value if not explicitly provided.

Have no idea whether or not this will help you. But if you want something
to happen when a control is clicked on you should use the OnClick event I
would think. If you use the standard Event Procedure setting for the OnClick
property then the form will have a controlname_OnClick subroutine in its code
section where you can write whatever routine you need to let something else
know the control was clicked and which one.
 
Ciao Melissa,

Following what Dick Goldbar wrote, I would add the following:

Where will MyFunction() be?

1. If it is in the form's module then MyFunction() could be:

Public Function MyFunction()

MsgBox "I'm in subform: " & Me.ActiveControl.Name
' your code etc.

End Function

The 'On enter' event property for each subform control should be:
=MyFunction()

2. If it is in a global module then MyFunction() should be:

Public Function MyFunction(rfrm As Form)

MsgBox "I'm in subform: " & rfrm.ActiveControl.Name
' your code etc.

End Function

The 'On enter' event property for each subform control should be:
=MyFunction([Form])

Cheers,

Mike Watson
Connecting Software
via Lodovico il Moro 87
20143 Milano, Italy
 
Back
Top