Sender address!!

K

klwemu

Hi

Here is a very simple function, that works not on WinXP Off2K System.
When i call the function approx. 5 times, VB crashs! When i deactivate
the Debug Line all is fine. So the problem is th access to the Sender
Object.
Have anybody ideas about the reason? I am using CD0 1.21

Function GetSenderData()
Dim session As MAPI.session
Dim messages As MAPI.messages
Dim inbox As MAPI.folder

Set session = CreateObject("MAPI.Session")
session.Logon NewSession:=False

Set inbox =
session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderInbox)

Debug.Print inbox.messages(1).Sender.Type ' <<< Crash Line!

' session.Logoff
' Set session = Nothing
' Set messages = Nothing

End Function
 
D

Dan Mitchell

(e-mail address removed) wrote in @o42g2000hsc.googlegroups.com:
Debug.Print inbox.messages(1).Sender.Type ' <<< Crash Line!

Which bit of this line crashes? If you do this, which one has the
problem?

mapi.messages messages = inbox.messages
mapi.message message = messages.getfirst
mapi.addressentry snd = message.sender
debug.print snd.type

Also, what happens if you uncomment the logout code at the end? What
happens if you log in once per run and use the same logged in session all
the time, rather than logging in once per getsenderdata call?

-- dan
 
K

klwemu

(e-mail address removed) wrote in @o42g2000hsc.googlegroups.com:


Which bit of this line crashes? If you do this, which one has the
problem?

mapi.messages messages = inbox.messages
mapi.message message = messages.getfirst
mapi.addressentry snd = message.sender
debug.print snd.type

Also, what happens if you uncomment the logout code at the end? What
happens if you log in once per run and use the same logged in session all
the time, rather than logging in once per getsenderdata call?

-- dan

Hi Dan!

The diasbled logout code does not happen to the problem. Enablend/
Disabled makes no difference.
It seems that the problem occours when i access (in any case) the
"Sender" Object up to 4-8 times.
klwemu
 
D

Dan Mitchell

(e-mail address removed) wrote in
The diasbled logout code does not happen to the problem. Enablend/
Disabled makes no difference.
It seems that the problem occours when i access (in any case) the
"Sender" Object up to 4-8 times.

What if you change the logout code to this?

session.Logoff
Set messages = Nothing ' so this is before changing session
Set session = Nothing

(otherwise, the messages object is pointing at a session that's been
cleared out, which might be causing problems).

What makes the difference between the times when it fails after 4 goes
and the times when it fails after 8 goes? How are you calling
GetSenderData?

If I start a new project, add a reference to CDO1.21, and put in this,
it works just fine for me (no logoff, and 100 tries).

Private Sub Form_Load()
For i = 1 To 100
GetSenderData
Next
End Sub

Function GetSenderData()
Dim session As MAPI.session
Dim messages As MAPI.messages
Dim inbox As MAPI.folder

Set session = CreateObject("MAPI.Session")
session.Logon NewSession:=False

Set inbox = session.GetDefaultFolder
(CdoDefaultFolderTypes.CdoDefaultFolderInbox)

Debug.Print inbox.messages(1).Sender.Type ' <<< Crash Line!
End Function


-- dan
 

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