KB 223245 problem

B

bibikoff

i think i find the better solution of the problem referenced in KB article 223245

create a new form frmTerminator:

Option Explicit

Private m_obj As Object
Private m_name As String

Private Sub Form_Close()
Debug.Print "frmTerminator.close"
End Sub

Private Sub Form_Load()
m_name = CStr(Timer)
colTerminatorForms.Add Me, m_name
End Sub

Public Sub SetObjectToTerminate(obj As Object)
Set m_obj = obj
Me.TimerInterval = 3000
End Sub

private Sub Form_Timer()
Me.TimerInterval = 0
Set m_obj = Nothing
colTerminatorForms.Remove m_name
Debug.Print "termination done!"
End Sub


create a standard module Module1:
Option Explicit
Public colTerminatorForms As New Collection

create a class module Class1:
Option Explicit
Private WithEvents fForm As Form

Sub Init(pForm As Form)
If fForm Is Nothing Then
Set fForm = pForm
End If
End Sub

Private Sub Class_Initialize()
Debug.Print "Object is initialized"
End Sub

Private Sub Class_Terminate()
Debug.Print "Object is terminated"
End Sub

create a form Form1:
Option Compare Database
Option Explicit

Private fObj As New Class1

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

fObj.Init Me

Exit_Form_Open:
Exit Sub

Err_Form_Open:
Cancel = True
MsgBox Err.Description
Resume Exit_Form_Open
End Sub

Private Sub Form_Close()
Dim t As New Form_frmTerminator
t.SetObjectToTerminate fObj
Set fObj = Nothing
End Sub


run the form Form1
and close it - GPF doesn't occurs!

sorry for my english :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top