![]() |
WithEvents problem
A strange one this. I have been using John Walkenbach's excellent tip
on how to trap events in a class so that multiple objects that I want to respond in the same way to a specific Event can reference a single line of code. Now a problem has arisen when trying to trap events for all Textboxes on a UserForm: it appears that not all the events are available to the WithEvents handler in the class...specifically I have no access to the BeforeUpdate, AfterUpdate, Enter, Exit events (and probably others). Although there is a Change event this runs after every change, not every update so is a bit cumbersome. Does anybody know why all the usual Events are not available? Or how to circumvent this? I did try trapping all Controls (the AfterUpdate event is available for that in a class) rather than all Textboxes and then within the AfterUpdate event determine if the TypeOf control was MSForms.Textbox but I got an error saying that that Event was not supported. Thanks a lot Lloyd |
WithEvents problem
As I understand it some events are inherited from the container object, the
UserForm here. Within the events class, you are effectively trapping a control's events outside of that container, so there is no access to inherited events (they aren't exposed by that control). -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "pinkfloydfan" wrote in message ups.com... A strange one this. I have been using John Walkenbach's excellent tip on how to trap events in a class so that multiple objects that I want to respond in the same way to a specific Event can reference a single line of code. Now a problem has arisen when trying to trap events for all Textboxes on a UserForm: it appears that not all the events are available to the WithEvents handler in the class...specifically I have no access to the BeforeUpdate, AfterUpdate, Enter, Exit events (and probably others). Although there is a Change event this runs after every change, not every update so is a bit cumbersome. Does anybody know why all the usual Events are not available? Or how to circumvent this? I did try trapping all Controls (the AfterUpdate event is available for that in a class) rather than all Textboxes and then within the AfterUpdate event determine if the TypeOf control was MSForms.Textbox but I got an error saying that that Event was not supported. Thanks a lot Lloyd |
WithEvents problem
On the second part of your question, you probably need a different approach.
One way that might work is to have some sort of commit button, and do all of the checks when that button is clicked. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "pinkfloydfan" wrote in message ups.com... A strange one this. I have been using John Walkenbach's excellent tip on how to trap events in a class so that multiple objects that I want to respond in the same way to a specific Event can reference a single line of code. Now a problem has arisen when trying to trap events for all Textboxes on a UserForm: it appears that not all the events are available to the WithEvents handler in the class...specifically I have no access to the BeforeUpdate, AfterUpdate, Enter, Exit events (and probably others). Although there is a Change event this runs after every change, not every update so is a bit cumbersome. Does anybody know why all the usual Events are not available? Or how to circumvent this? I did try trapping all Controls (the AfterUpdate event is available for that in a class) rather than all Textboxes and then within the AfterUpdate event determine if the TypeOf control was MSForms.Textbox but I got an error saying that that Event was not supported. Thanks a lot Lloyd |
WithEvents problem
Those events are inherited from the container object (Control). So you can't
trap them with With Events to the best of my knowledge. -- Regards, Tom Ogilvy "pinkfloydfan" wrote: A strange one this. I have been using John Walkenbach's excellent tip on how to trap events in a class so that multiple objects that I want to respond in the same way to a specific Event can reference a single line of code. Now a problem has arisen when trying to trap events for all Textboxes on a UserForm: it appears that not all the events are available to the WithEvents handler in the class...specifically I have no access to the BeforeUpdate, AfterUpdate, Enter, Exit events (and probably others). Although there is a Change event this runs after every change, not every update so is a bit cumbersome. Does anybody know why all the usual Events are not available? Or how to circumvent this? I did try trapping all Controls (the AfterUpdate event is available for that in a class) rather than all Textboxes and then within the AfterUpdate event determine if the TypeOf control was MSForms.Textbox but I got an error saying that that Event was not supported. Thanks a lot Lloyd |
WithEvents problem
Thanks for the clear answers guys
I'm thinking then that perhaps I can trap the events for the userform, then with the BeforeUpdate event check that a Textbox has the focus before running my code... Just out of interest, do you have the same WithEvents limitations if coding directly in VB rather than VBA? All the best Lloyd |
All times are GMT +1. The time now is 02:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com