Event Coller Question

  • Thread starter Thread starter Luca Giannoni
  • Start date Start date
L

Luca Giannoni

Hi to everybody,

I have this problem

I attach an event to a group of control from code:
Set Frm = Fom_Test
for ii = 1 to 100
Frm.Controls("Label" & ii).OnClick = "=Event_Click()"
Next

Event_Click() is on form Form_Test

Sub Event_Click()
' code to apply to label caller
End Sub

when the event "raise" I need to know wich object (label) call the event.

Someone could help me?

thanks in advance

Luca
 
Luca Giannoni wrote
I attach an event to a group of control from code:
Set Frm = Fom_Test
for ii = 1 to 100
Frm.Controls("Label" & ii).OnClick = "=Event_Click()"
Next

Event_Click() is on form Form_Test

Sub Event_Click()
' code to apply to label caller
End Sub

when the event "raise" I need to know wich object (label) call the event.


You should use the syntax:
Set Frm = Forms!Test
instead of the Form_Test reference. Or, if your code is in
the form's module, then use:
Set Frm = Me
which is just an extra step when you could use Me instead of
Frm in the rest of the procedure.

If these "Label" controls are text boxes, then you can use
the ActiveControl property to refer to the control object
that triggered the event.

However, if the controls are in fact label controls, that
won't work because a label can not receive the focus and
will never be the active control. In this case, you can try
setting the OnClick property to:

Frm.Controls("Label" & ii).OnClick = "=Event_Click(""" _
& Frm.Controls("Label" & ii).Name & """)"
and

Sub Event_Click(strName As String)
Dim lbl As Label
Set lbl = Me(strName)
' code to apply to label caller
End Sub
 
Back
Top