Events

Standard code modules have no way of handling events.
Class modules can expose events.
link to WithEvents keyword


Declare Custom Events

Class Class_One 

Public Event event_Name(ByVal myArgument As String)
Public Event event_BeforeClose(ByRef Cancel As Boolean)

Raising the Event

Class Class_One 

Public Sub Method_Something
   RaiseEvent event_Name("text")

   Dim bcancel As Boolean
   RaiseEvent event_BeforeClose(bcancel)
   If (bcancel = True) Then
   End If
End Sub

Class_Initialize

Occurs when an instance of the associated class is created.
Lets you control what happens when an instance is created
Occurs when the instance is first created
Lets you initialize property values
Lets you create references to other objects
This cannot take any parameters.
The statements part consists of zero or more code statements to be run when the class is initialized

Class Class_One 

   Private Sub Class_Initialize()
'statements
   End Sub

End Class

This event is fired when an instance of the class is created

Set oClass = New Class_One 

Creating

To add this event choose Class from the top left drop-down and then Initialize from the top right drop-down


Class_Terminate

Occurs when an instance of the associated class is terminated.
Occurs when the last reference to the object is released
This might happen when a variable goes out of scope
This might happen when the object is explicitly set to Nothing
Lets you perform clean up tasks

Class Class_One 

   Private Sub Class_Terminate()
'statements
   End Sub

End Class

This event is fired when a class object is destroyed

Set oClass = Nothing 

Creating

To add this event choose Class from the top left drop-down and then Terminate from the top right drop-down



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext