PDA

View Full Version : Trapping UserForm Events In A Seperate Class



ChloeRadshaw
06-04-2009, 04:42 AM
I have built up a userform which contains a multipage and frame inside it.

I want to set textbox values and write action handlers in a seperate class so I can keep things clean.

I have tried to capture the events raised from the userform directly with no success.

Do I have to trap the events for each control I am interested in explicitly or can I just do: UserForm.myButton_click.

I also have tried this :



WithEvents eventIdTestBoxListener As TextBox


But I get a object does not support automation events error.

Please help!!!

mikerickson
06-04-2009, 06:21 AM
Try putting this in a class module
Public WithEvents myBox As msforms.TextBox

ChloeRadshaw
06-04-2009, 12:03 PM
Yup - Thats it

Awesome - Thanks

Is there a way of getting a class to trap all events which happen on a form including all its children?

Put another way if you have a user form and two text boxes on there how can I trap all events I want too without explcitly asking for events of each component

mikerickson
06-06-2009, 06:52 AM
The class would have to have a property for each type of control or you could have it use msforms.Control which only has 4 propreties.