Outlook 2000 - folder copy on Application_quit event not possible

  • Thread starter Thread starter Wolfgang
  • Start date Start date
W

Wolfgang

Hello!

I am using Outlook 2000 SP3.

I want to copy my contact folder to a backup folder, when Outlook quit.

This is my code:

Private Sub Application_Quit()
MsgBox ("Start_Quit")
Set myNameSpace = Application.GetNamespace("MAPI")
Set mystore_ p= myNameSpace.Folders("personal_store")
Set mystore_b = myNameSpace.Folders("archiv_store")

Set myfolder = mystore_p.Folders("contact")
Call myfolder.CopyTo(mystore_b)

MsgBox ("End_Quit")
End Sub

I get the runtimeerror "-2147467259 (80004005)" in code line
"Set mystore_ p= myNameSpace.Folders("personal_store")"

Exists a known solution for this problem?

Thanks
Wolfgang
 
Application_Quit is way too late. By that time, all Outlook objects are
unavailable. Instead, you need to monitor for the closing of the last
Explorer object.

You also will have a problem the second time your code runs because the
folder will already exist in the target store and folder names must be
unique. You'll have to decide how you want to handle that -- maybe delete
the old copy before adding the new?
 
Thanks for your reply!

I have tried the following implementation:



Option Explicit

Dim WithEvents ae As Outlook.Explorer


Sub Application_Startup()
Set ae = Application.ActiveExplorer
End Sub



Private Sub ae_Close()
MsgBox "ae_Close"
End Sub



Private Sub ae_FolderSwitch()
MsgBox "ae_FolderSwitch"
End Sub



The "FolderSwitch"-event fires as expected, but when I close Outlook the
"Close"-event did not occur. When I look in the TaskManager the
Outlook-Process is not running -> the whole Outlook-Application has quit. Is
there something else to do?



Thanks

Wolfgang
 
You should add code to handle the case where the first Explorer is closed
but another one is still open:

Dim WithEvents m_objExpl As Outlook.Explorer

Private Sub Application_Startup()
Set m_objExpl = Application.ActiveExplorer
End Sub

Private Sub m_objExpl_Close()
If Application.Explorers.Count > 0 Then
Set m_objExpl = Application.ActiveExplorer
Else
' shut down code goes here
Set m_objExpl = Nothing
Set m_objContact = Nothing
End If
End Sub

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks for your sample code!



This sample only works, when I open two explorers and then close the first
one while the second is still open.

If I close the second and then the first one the close event did not occur.
It´s the same, when I only open one explorer.

It looks like that the explorer object is destroyed, before the closing
event can occur.



Wolfgang
 
Back
Top