I have a very simple form, that uses a very simple class to handle some things. And that class has a Class_Terminate
sub to clean up after itself. However, that doesn't seem to be firing when the form gets closed.
MCVE:
Form Form1, one text box named Text0, no further controls
Private myClass1 As Class1Private Sub Form_Load() Set myClass1 = New Class1 myClass1.InitForm MeEnd Sub
Class Class1
Public theForm As FormPrivate WithEvents SomeTextbox As TextBoxPublic Sub InitForm(frm As Form) Set theForm = frm Set SomeTextbox = frm.Text0End SubPrivate Sub Class_Terminate() MsgBox "Class1 terminated succesfully"End Sub
However, the class terminate handler doesn't fire when I close the form.
I tried unsetting the Form object in the class:
Private Sub Form_Unload(Cancel As Integer) Set myClass1.theForm = NothingEnd Sub
But chaos ensued: The class terminate handler fires after closing the form, but immediately afterwards Access hard-crashes without any error message!