Terminate Event - Event Procedure

Terminate Event — Event Procedure

See Also         Example

To create the event procedure for the Terminate event, open the class module and click Class in the Object box. Then click Terminate in the Procedure box.

Syntax

Private Sub Class_Terminate( )

Remarks

To remove a reference to an instance of a class from memory, you can set the variable to which that reference is assigned to Nothing. For example, suppose you've created an instance of a class named CustomObject and assigned it to an object variable named obj. When you set obj to Nothing, the reference is removed from memory. Once all references to the instance of the class have been removed from memory, the Terminate event occurs.

A reference to an instance of a class will also be removed from memory when the object variable to which it's assigned goes out of scope. For example, if the variable is defined within a procedure, it will go out of scope when the procedure has finished running. If the variable is defined at the module level in a standard module, it will go out of scope when the code is reset. If all references to an instance of a class are removed in this way, the Terminate event also occurs.

The Terminate event isn't triggered if instances of a class were removed from memory because Microsoft Access terminated abnormally. For example, if your code invokes the Quit method of the Microsoft Access Application object before removing all existing instances of the class from memory, the Terminate event isn't triggered for that class.