Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event trigger problems

Status
Not open for further replies.

wbeetge

Programmer
May 2, 2002
57
ZA
I have a class that needs to triger and event in an ActiveX.
The AX needs to trigger an event to the form based on the information sent in the trigger from the class to the AX
Example
I need to see a True value when the event has triggered in the form. The class processes and sends the result True or False to the AX and raises an event to the AX. The AX determines if it is True or False and acts on the False by itself, but needs to raise an event to the Form if it is True.

I can't get the event to trigger in the AX raised from the class.
Any ideas why ?
 
Use WithEvents in your Class, Control and Form.

Create your events in your class and control

Let's say the call tree is like this:

Form -> Control -> Class

The form has a control and the control refers to a class. You want the class to raise an event back to the control and you want the control to raise an event back to the form.

The form should be able to see the events from the control. The trick is to get the control to get the event back from the class.

Declare your event in the Class.

Then in the Control, declare your variable like this:

Private WithEvents objClass As MyEventClass

MyEventClass is whatever the name of your class is.

Now you should be able to see the events of the class in the declaration section of the control. Just put your code here to handle the value and raise an event back to the form.

Try to refrain from using AX without explaining what it is, it makes it hard to understand what you're asking. Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Thanks Snaggs.

I have done it this way, but could not get the event to fire in the ActiveX from the class. It worked from the Activex to the Form however.

Please check this question again - I will follow through your suggestions and post the result back here.

Graham
 
Graham,

Be sure you use the "RaiseEvent" statement in your Class so it knows to fire the event on the Class. Also be sure you have your Class declared using "WithEvents" at the top of the ActiveX control. Once you declare it using WithEvents, you should have access to all the events in the Class from your ActiveX control. I'm sure you already know this, but you have to instantiate your Class by some method like this:

Set objMyClass = New MyClass

...before is can raise events back to the control. In otherwords, you have to create and instance of the Class in the Control.

Hope that helps, Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Snaggs.

Thank you again. give me a few minutes and I'll let you know.
If it still does'nt work, could I mail you the form, ActiveX and class with the code I've got to look at ?
 
Lovely.

I think the reason it didn't work, was the instancing of the class in the ActiveX.

Private Sub UserControl_Initialize()
Set myClassEvent = new myClass
End Sub

I had to use the New keyword. Is that correct ?
 
To Snaggs:

Thanks. It works perfectly. From all of the examples I've tried, yours was to the point and correct.
 
Yes you have to use the NEW command. That's what creates the instance of the class. Glad you were able to get it to work. Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top