Source object of an event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In some of my access forms, I have many controls with essentially identical
event handlers. Instead of having seperate event handling subs I would like
them to use the same sub, as this would lessen the amount of code
considerably.

I guess this could be solved by using a macro to handle the event, but in
that case I need a reference to the control that caused the event. How do I
obtain such a reference?
 
Daniel,

This is a fairly standard request.

1. Create a public function in a standard module, to handle the event
actions.

2. In each control's event property (the property, not the event), add the
name of the function prepended by the equals sign (=), like so:
=MyFunc()

The public function must be a function, not a sub.

If your new event handler needs to know which control it's working with, use
Screen.ActiveControl.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
That's great, thank you very much!

Graham R Seach said:
Daniel,

This is a fairly standard request.

1. Create a public function in a standard module, to handle the event
actions.

2. In each control's event property (the property, not the event), add the
name of the function prepended by the equals sign (=), like so:
=MyFunc()

The public function must be a function, not a sub.

If your new event handler needs to know which control it's working with, use
Screen.ActiveControl.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top