ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Writing code for Events in Class (https://www.excelbanter.com/excel-programming/393405-writing-code-events-class.html)

Bart[_6_]

Writing code for Events in Class
 
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


NickHK

Writing code for Events in Class
 
Bart,

Dim WithEvents SomeVar As SomeControl

NickHK

"Bart" wrote in message
ups.com...
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




Bart[_6_]

Writing code for Events in Class
 
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


tissot.emmanuel

Writing code for Events in Class
 
Hi,

Try this way:

Private WithEvents txtControl As MSForms.TextBox

regards,

Manu/

"Bart" a écrit dans le message de news:
...
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




Bart[_6_]

Writing code for Events in Class
 
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





Bob Phillips

Writing code for Events in Class
 
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)

"Bart" wrote in message
ps.com...
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




Bart[_6_]

Writing code for Events in Class
 
Thanks Bob! That makes sense.

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

Bart


Bob Phillips

Writing code for Events in Class
 
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)

"Bart" wrote in message
ups.com...
Thanks Bob! That makes sense.

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

Bart




Bart[_6_]

Writing code for Events in Class
 
Ok. Thanks again Bob.
I think I can manage with the Change Event.

Bart


Bart[_6_]

Writing code for Events in Class
 
I found out that in MS Access the 'AfterUpdate' Event IS available by
using WithEvents. That's not fair!



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com