WithEvents problem

P

pinkfloydfan

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
 
B

Bob Phillips

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)
 
B

Bob Phillips

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)
 
G

Guest

Those events are inherited from the container object (Control). So you can't
trap them with With Events to the best of my knowledge.
 
P

pinkfloydfan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top