Skip to main content
edited tags
Link
Erik A
  • 32.8k
  • 13
  • 48
  • 74
Copy-paste in the wrong place fixed
Source Link
Erik A
  • 32.8k
  • 13
  • 48
  • 74

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 Class1
Private WithEvents SomeTextbox As Access.Textbox

Private Sub Form_Load()
    Set myClass1 = New Class1
    myClass1.InitForm Me
End Sub

Class Class1

Public theForm As Form
Private WithEvents SomeTextbox As TextBox
Public Sub InitForm(frm As Form)
    Set theForm = frm
    Set SomeTextbox = frm.Text0
End Sub
Private 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 = Nothing
End Sub

But chaos ensued: The class terminate handler fires after closing the form, but immediately afterwards Access hard-crashes without any error message!

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 Class1
Private WithEvents SomeTextbox As Access.Textbox

Private Sub Form_Load()
    Set myClass1 = New Class1
    myClass1.InitForm Me
End Sub

Class Class1

Public theForm As Form
Private WithEvents SomeTextbox As TextBox
Public Sub InitForm(frm As Form)
    Set theForm = frm
    Set SomeTextbox = frm.Text0
End Sub
Private 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 = Nothing
End Sub

But chaos ensued: The class terminate handler fires after closing the form, but immediately afterwards Access hard-crashes without any error message!

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 Class1

Private Sub Form_Load()
    Set myClass1 = New Class1
    myClass1.InitForm Me
End Sub

Class Class1

Public theForm As Form
Private WithEvents SomeTextbox As TextBox
Public Sub InitForm(frm As Form)
    Set theForm = frm
    Set SomeTextbox = frm.Text0
End Sub
Private 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 = Nothing
End Sub

But chaos ensued: The class terminate handler fires after closing the form, but immediately afterwards Access hard-crashes without any error message!

Source Link
Erik A
  • 32.8k
  • 13
  • 48
  • 74

Class_Terminate not firing on object from form

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 Class1
Private WithEvents SomeTextbox As Access.Textbox

Private Sub Form_Load()
    Set myClass1 = New Class1
    myClass1.InitForm Me
End Sub

Class Class1

Public theForm As Form
Private WithEvents SomeTextbox As TextBox
Public Sub InitForm(frm As Form)
    Set theForm = frm
    Set SomeTextbox = frm.Text0
End Sub
Private 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 = Nothing
End Sub

But chaos ensued: The class terminate handler fires after closing the form, but immediately afterwards Access hard-crashes without any error message!