Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime (Latebound) control withevents Post Tenebras Lux Excel Programming 0 August 27th 06 04:18 AM
WithEvents of MSForms.Textbox AMDRIT Excel Programming 2 November 4th 05 06:00 PM
WithEvents Ronin Excel Programming 2 August 20th 05 09:59 PM
Using Class, WithEvents and auto-instanciating Tetsuya Oguma[_2_] Excel Programming 0 September 5th 03 03:22 AM
Can't dynamically add withevents OptionButton to worksheet onedaywhen Excel Programming 6 August 27th 03 09:11 AM


All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"