Create MAPI Session failure

D

derek mang

I am using Windows XP pro with Office 2003. Within Outlook, I have a
series of macros to facilitate handling of specific emails.

Within this, one function is to extract the sender's email address using
CDO - which fails (Code below). I use the same .otm file on a different
machine wito Windows XP pro and Outlook 2002, and it's perfect.

CDO 1.21 is referenced.


Any thoughts would be appreciated
Regards
Derek

Option Explicit

Public G_objSession As MAPI.Session

Sub SetCDOSession()

' start CDO session
Set G_objSession = CreateObject("MAPI.Session")
G_objSession.Logon , , False, False

End Sub

Sub UnsetCDOSession()

' start CDO session
Set G_objSession = Nothing

End Sub

Function GetFromAddress(objMsg As MailItem) As String

Dim strEntryID As String
Dim strStoreID As String
Dim objCDOItem As MAPI.Message

' get EntryID and StoreID for message
strEntryID = objMsg.EntryID
strStoreID = objMsg.Parent.StoreID


If G_objSession Is Nothing Then
' Set the CDO Session up as it doesn't exist.
Call SetCDOSession
End If

' pass item to CDO and get sender address
On Error Resume Next
Set objCDOItem = G_objSession.GetMessage(strEntryID, strStoreID)

GetFromAddress = objCDOItem.Sender.Address

Set objCDOItem = Nothing

End Function
 
K

Ken Slovak - [MVP - Outlook]

You can't run code in an OTM file in Outlook 2003 SP2 or higher I believe it
is. You can only run code from published forms.
 
S

Sue Mosher [MVP-Outlook]

You're thinking of an .oft file, I think. .otm would be VBA. The most likely cause is that CDO 1.21 isn't installed on the problem machine.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Ken Slovak - said:
You can't run code in an OTM file in Outlook 2003 SP2 or higher I believe it
is. You can only run code from published forms.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


derek mang said:
I am using Windows XP pro with Office 2003. Within Outlook, I have a
series of macros to facilitate handling of specific emails.

Within this, one function is to extract the sender's email address using
CDO - which fails (Code below). I use the same .otm file on a different
machine wito Windows XP pro and Outlook 2002, and it's perfect.

CDO 1.21 is referenced.


Any thoughts would be appreciated
Regards
Derek

Option Explicit

Public G_objSession As MAPI.Session

Sub SetCDOSession()

' start CDO session
Set G_objSession = CreateObject("MAPI.Session")
G_objSession.Logon , , False, False

End Sub

Sub UnsetCDOSession()

' start CDO session
Set G_objSession = Nothing

End Sub

Function GetFromAddress(objMsg As MailItem) As String

Dim strEntryID As String
Dim strStoreID As String
Dim objCDOItem As MAPI.Message

' get EntryID and StoreID for message
strEntryID = objMsg.EntryID
strStoreID = objMsg.Parent.StoreID


If G_objSession Is Nothing Then
' Set the CDO Session up as it doesn't exist.
Call SetCDOSession
End If

' pass item to CDO and get sender address
On Error Resume Next
Set objCDOItem = G_objSession.GetMessage(strEntryID, strStoreID)

GetFromAddress = objCDOItem.Sender.Address

Set objCDOItem = Nothing

End Function
 
K

Ken Slovak - [MVP - Outlook]

You're right of course, too many abbreviations to keep track of <sound of
slapping upside head>




You're thinking of an .oft file, I think. .otm would be VBA. The most likely
cause is that CDO 1.21 isn't installed on the problem machine.
 

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