Personal Folder not closed properly

G

Guest

Many hours after running code, Outlook has an error message upon opening
(each time it opens now--even though the code ran once hours ago) that the
Personal Folder was not closed properly, and goes through a 6 minute
assessment and fix, and then finally opens.

Do ALL of these "sets" need to be Set to = Nothing at the end of the
routine, or just the myOlApp?

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myPersonal = myNameSpace.Folders("Personal Folders2")
 
D

Dmitry Streblechenko

This is an indication that you code was terminated without releasing one of
the Outlook objects (which referenced a MAPI object).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guest

Thanks for the quick response.

Can I:

A. Go back in and do something like this to fix it
Set myOlApp = Nothing
Exit Sub

B. Go back in and do this for ALL the Set statements?
 
D

Dmitry Streblechenko

No, once it is damaged, it needs to be fixed.
VB automatically releases all COM objects, so most likely your code
terminates abnormally (e.g. if your app is killed in the Task Manager)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guest

I'm a little confused.

I asked whether I should fix it by setting Set statements = Nothing

And you said, > No, once it is damaged, it needs to be fixed.

So setting them to = Nothing will not work, but I need to fix it somehow.

How do I fix it? Are you talking Registry or something?

I know that in the future, when I run the whole process, I'll have Set xxx =
Nothing at the end of the sub routine ... but what can I do at this point to
undo the fact that I never had those statements to close out those
"variables"?
 
D

Dmitry Streblechenko

You can set COM objects to Nothing to force VB to immediately release the
object, but you don't have to - VBwill automatically release the object when
the variable goes out of scope. For the local variable that wowuldd be when
the sub exits. For the global objects thaa t will be when the app exits.
If you kill your app using the Task Manager or if it crashes, VB runtime
does not get a chance to run its cleanup code.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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