You can add events in ActiveX Controls, Class modules and Forms.
You first have to declare the event:
If the above is declared in a class module or a form you have to use the WithEvents keyword to get the event procedure. If it's in an ActiveX Control this isn't necassary because all events are visible when you add the control to a form.Code:Public Event MyCustomEvent() Public Sub SomeMethod() RaiseEvent MyCustomEvent End Sub
Let's say you used the above in a class module (named MyClass), and you want to use that class in a form. Then you could use code simular to this
Best regardsCode:'a form Private WithEvents obj As MyClass Private Sub Form_Load() Set obj = New MyClass obj.SomeMethod End Sub Private Sub obj_MyCustomEvent() MsgBox "MyCustomEvent was fired!", vbInformation End Sub




Reply With Quote