ThisOutlookSession variable resetting to empty

R

reesd

I am having a problem with variables being set back to empty after a sub or
function completes. It seems to have recently come up in code that I thought
used to work so I am wondering if its some sort of Outlook setting (or
security hotfix) or if I am just missing something obvious.

If I place the following code in ThisOutlookSession and step though the Sub
I see that sentbox is properly set, but the moment I step out of the Sub it
goes back to Empty.

Any thoughts?

Thanks,

d

Option Explicit
Private WithEvents sentbox As Items
Public Sub TestSetup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set sentbox = objNS.GetDefaultFolder(olFolderSentMail).Items
End Sub
 
T

TC

Are you sure that objNS.GetDefaultFolder(olFolderSentMail).Items is not
actually returning Empty? Add this before end sub, to check: msgbox
isempty(sentbox)

And the obvious one, check that sentbox /is/ actually defined outside
TestSetup, not inside it :)

HTH,
TC
 
R

reesd

My example is a cut and paste of the entire ThisOutlookSession module. So the
variable is clearly defined outside it.

I already verified using the debugger that Items is not returning Empty. To
double-check I changed the code to the following. "Items" is printed when the
Sub is run, but if I do
? TypeName(sentbox)
it returns "Empty".

Thanks,

d

Option Explicit
Private WithEvents sentbox As Items
Public Sub TestSetup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set sentbox = objNS.GetDefaultFolder(olFolderSentMail).Items
Debug.Print TypeName(sentbox)
End Sub
 

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