Writing code for Events in Class

  • Thread starter Thread starter Bart
  • Start date Start date
B

Bart

Hello,

Is it possible to write code for an Event of a control in a class
module?
I wrote a Class Module where I can set a TextBox control. I would like
to have the class to handle the AfterUpdate event of this TextBox
control.

Thanks in advance,

Bart
 
Very nice construction. Thanks NickHK for the tip!

It seems that the AfterUpdate Event is part of the MSForms.Control
Class.
So I'm using the following declaration to get the AfterUpdate event:

Private WithEvents txtControl As MSForms.Control

Now the Events become available in the PickMenu for implemenation.

While running the code with the line where I set the TextBox to this
txtControl, it gives an error:

Run-Time Error '459':
Object or Class does not support the set of events

I don't get it. What does this mean?
I did some playing with implementing Events part of the
MSForms.Textbox Class. That worked correctly.

Bart
 
Hi,

Try this way:

Private WithEvents txtControl As MSForms.TextBox

regards,

Manu/
 
Manu,

The AfterUpdate Event doesn't come available when declaring a variable
as MSForms.TextBox Class with Events. I think the MSForms.TextBox
inherits the Event from the MSForms.Control Class.

Why doesn't the AfterUpdate Event becomes available by Inheritance?

Bart
 
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). AfterUpdate is one
of these.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thanks Bob! That makes sense.

There's no other way to trap the AfterUpdate Event inherted by the
TextBox outside its Container (UserForm)?

Bart
 
Don't think so, I use the Change event in the class and AfterUpdate in the
form. A pain, but unavoidable I believe.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
I found out that in MS Access the 'AfterUpdate' Event IS available by
using WithEvents. That's not fair!
 

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

Back
Top