Closing Objects in Quit Event - Is Graceful Quit Possible?


Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA RSS
Next:  Are BCM Business Project templates possible.  
Author Message
GrowWiser



Joined: Aug 23, 2007
Posts: 1



PostPosted: Thu Aug 23, 2007 10:00 pm    Post subject: Closing Objects in Quit Event - Is Graceful Quit Possible?

I am using Outlook 2007 on XP. It appears that Application.Quit event does not act like a Destructor. Outlook seems to clear all objects before entry into the event so there is no way to gracefully shutdown the application. Furthermore, it clears objects in such a way that class module's Terminate event is not called. Is this really correct?

I've stripped a large VBA app into a small piece of test code that demonstrates the issue - you'll find it below.

If you run Process Explorer you will see that IE never shuts down because IE.quit needs to run. If you uncomment IE.quit in Application_Quit event Outlook will crash because the IE object is no longer there.

Furthermore, there is a MsgBox in the StoreManager Terminate event. This message box never shows up showing that the destructor never runs.

However, Outlook clears these objects, it does so before the Quit event and in a way that does not all the object's destructor.

Please tell me I am missing something...this seems too terrible to be true as it would mean there is no way to gracefully showdown a VBA app.

-----CODE START------

Public ie As Object
Private test As StoreManager

Public Sub Initialize_Handler()
Set ie = CreateObject("internetexplorer.application")
ie.Navigate "about:blank"
Do
DoEvents
Loop While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
ie.Visible = True
Set test = New StoreManager
End Sub

Private Sub Application_Quit()
' ie.Quit
Set ie = Nothing
Set test = Nothing

MsgBox "OK to end"
End Sub

Private Sub Application_Startup()
Initialize_Handler
Stop
End Sub

Public Function ProcessManualTasks()

'Initialize_Handler

'ie.Quit
'Set ie = Nothing
'Quit
End Function

------CODE END------
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum