MAPI.Session don't work in Microsoft® Office Outlook® 2003

A

Alex

Hello All,

Before a question, I describe my System -soft and hardware:

Hardware
Processor: Intel® Xeon™ CPU 2.80GHz
Mamory: 1024MB RAM
DirectX Version: DirectX 9.0b

Software
Operating System: Microsoft Windows 2000 Professional (5.0, Build 2195)
Microsoft® Office Outlook® 2003(11.6401.6408) SP1 (Part of microsoft office
Proffessional Edition 2003)

Here is my code. I took the example from here
http://www.outlookcode.com/d/code/selectnames.htm and modified it a bit for
my needs.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Function GetOneNameViaCDO()
Const cdoE_USER_CANCEL = &H80040113
Dim strAccount
Dim strOffice_Location
Dim strEntryID
Dim strDISPLAY_NAME
Dim strTITLE
Dim strCOMPANY_NAME
Dim strDISPLAY_NAME_PREFIX
Dim strSURNAME
Dim strMIDDLE_NAME
Dim strPR_GIVEN_NAME
Dim strBusiness_Telephone_Number
Dim strMOBILE_TELEPHONE_NUMBER
Dim msg
Dim str


Dim strContact_EmailOriginalDisplayName
Dim strContact_EmailEmailAddress
Dim strContact_EmailAddrType
Dim strPR_EMAIL 'SMTP e-mail address

'VBScript does not recognize constants!
' Define them explicitly or use their value.
Dim cdoPR_Account
Dim cdoPR_Office_Location
Dim cdoPR_EntryID
Dim cdoPR_DISPLAY_NAME
Dim cdoPR_TITLE
Dim cdoPR_COMPANY_NAME
Dim cdoPR_DISPLAY_NAME_PREFIX
Dim cdoPR_SURNAME
Dim cdoPR_MIDDLE_NAME
Dim cdoPR_GIVEN_NAME
Dim cdoPR_Business_Telephone_Number
Dim cdoPR_MOBILE_TELEPHONE_NUMBER

Dim cdoContact_EmailOriginalDisplayName
Dim cdoContact_EmailEmailAddress
Dim CdoContact_EmailAddrType
Dim CdoPR_EMAIL 'SMTP e-mail address
Dim vbCRLF

Const CdoPropSetID3 = "0420060000000000C000000000000046"
cdoPR_Account = &H3A00001E
cdoPR_Office_Location = &H3A19001E
cdoPR_EntryID = &HFFF0102
cdoPR_DISPLAY_NAME = &H3001001F
cdoPR_TITLE = &H3A17001F
cdoPR_COMPANY_NAME = &H3A16001F
cdoPR_DISPLAY_NAME_PREFIX = &H3A45001E
cdoPR_SURNAME = &H3A11001E
cdoPR_MIDDLE_NAME = &H3A44001F
cdoPR_GIVEN_NAME = &H3A06001F
cdoPR_Business_Telephone_Number = &H3A08001F
cdoPR_MOBILE_TELEPHONE_NUMBER = &H3A1C001F

cdoContact_EmailOriginalDisplayName = "{" & CdoPropSetID3 & "}" & "0x8084"
cdoContact_EmailEmailAddress = "{" & CdoPropSetID3 & "}" & "0x8083"
CdoContact_EmailAddrType = "{" & CdoPropSetID3 & "}" & "0x8082"
CdoPR_EMAIL = &H39FE001E
vbCRLF = Chr(13) & Chr(10)


'Dim oSession, oNamespace, oApp
'Set oApp = CreateObject("Outlook.Application")
'Set oNamespace = oApp.GetNamespace("MAPI")
'Set oSession = oApp.CreateObject("MAPI.Session")
'objSession = oSession

' start CDO session
Set objSession = CreateObject("MAPI.Session")

objSession.Logon , , False, False


On Error Resume Next
Set colCDORecips = objSession.AddressBook(, _
"Pick a Person to conatact over VoIP", , , 1, _
"My Contact Partner")


If Err = 0 Then
If colCDORecips.count <> 1 Then
MsgBox "Please choose exactly 1 name.", , _
"Chose One Name"
Else

strAccount =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_Account)
strOffice_Location =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_Office_Location)
strEntryID =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_EntryID)
strDISPLAY_NAME =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_DISPLAY_NAME)
strTITLE = colCDORecips.Item(1).AddressEntry.Fields(cdoPR_TITLE)
strCOMPANY_NAME =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_COMPANY_NAME)
strDISPLAY_NAME_PREFIX =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_DISPLAY_NAME_PREFIX)
strSURNAME =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_SURNAME)
strMIDDLE_NAME =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_MIDDLE_NAME)
strPR_GIVEN_NAME =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_GIVEN_NAME)
strBusiness_Telephone_Number =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_Business_Telephone_Number)
strMOBILE_TELEPHONE_NUMBER =
colCDORecips.Item(1).AddressEntry.Fields(cdoPR_MOBILE_TELEPHONE_NUMBER)

strContact_EmailOriginalDisplayName =
colCDORecips.Item(1).AddressEntry.Fields(cdoContact_EmailOriginalDisplayName)
strContact_EmailEmailAddress =
colCDORecips.Item(1).AddressEntry.Fields(cdoContact_EmailEmailAddress)
strContact_EmailAddrType =
colCDORecips.Item(1).AddressEntry.Fields(CdoContact_EmailAddrType)
strPR_EMAIL = colCDORecips.Item(1).AddressEntry.Fields(CdoPR_EMAIL)


Debug.Print "---------------------------"
Debug.Print "strAccount: " & strAccount
Debug.Print "strOffice_Location: " & strOffice_Location
Debug.Print "strEntryID: " & strEntryID
Debug.Print "strDISPLAY_NAME: " & strDISPLAY_NAME
Debug.Print "strTITLE: " & strTITLE
Debug.Print "strCOMPANY_NAME: " & strCOMPANY_NAME
'Debug.Print "strDISPLAY_NAME_PREFIX: " & strDISPLAY_NAME_PREFIX
Debug.Print "strSURNAME: " & strSURNAME
'Debug.Print "strMIDDLE_NAME: " & strMIDDLE_NAME
Debug.Print "strPR_GIVEN_NAME: " & strPR_GIVEN_NAME
Debug.Print "strBusiness_Telephone_Number: " &
strBusiness_Telephone_Number
Debug.Print "strMOBILE_TELEPHONE_NUMBER: " &
strMOBILE_TELEPHONE_NUMBER

'Debug.Print "strContact_EmailOriginalDisplayName: " &
strContact_EmailOriginalDisplayName
'Debug.Print "strContact_EmailEmailAddress: " &
strContact_EmailEmailAddress
'Debug.Print "strContact_EmailAddrType: " &
strContact_EmailAddrType
Debug.Print "strPR_EMAIL: " & strPR_EMAIL
Debug.Print "---------------------------"


If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return " & _
"a name, because " & _
"you clicked No on the " & _
"e-mail address access " & _
"dialog. You need to try " & _
"again and click Yes " & _
"this time.", , _
"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If

GetOneNameViaCDO = strBusiness_Telephone_Number


' release objects
objSession.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing
End Function
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Ok, now comes my Problem.
I try to access to the GAL (Global Address List). The code above works in
Microsoft® Office Outlook® 2000 without any problems. Now I have installed a
Microsoft® Office Outlook® 2003 and it does not work anymore. I always get an
Exception "Run-time error -142…(ab4401f3)' The operator failed"

I tried to debug the code and I have found out that the exception happens
at the line:
Set objSession = CreateObject("MAPI.Session").

The installed CDO versions are "Microsoft CDO for NTS 1.2 Library" and
"Microsoft CDO for Windows 2000 Library"


Please help me.

Thanks a lot
Alex

PS: Maybe have anybody an idea how I can access a GAL without CDO or
MAPI.Session?
 
N

neo [mvp outlook]

Check to see if you have a file named CDO.DLL at \Program Files\Common
Files\System\MSMAPI\<LANGID>. The reason that I ask is that Office/Outlook
2003 doesn't install the library by default and the 2 you gave are not the
right flavors. If it is missing like suspect, just go thru add/remove and
add the component Collaboration Data Objects 1.21. (Its under the Outlook
section)

If CDO.DLL is present, try registering it. (e.g. regsvr32 cdo.dll)
 
A

Alex

Thanks a lot for your answer and your suggestion. It was effective. It is
working.

If it is not difficult for you, could you please answer one further question.

I am working for a big company and actually I need a programmatic access to
GAL inside one Office Application written in VBScript for Outllok. The usage
of CDO1.21 (as you proposed) would require the installation or update of
several thousends computers by our IT-support department, which makes it very
difficult and almost impossible, because they will most likely refuse to do
it.

Dou you have an idea, how one can programmatically call/use GAL dialog
without using CDO1.21 ?

Thanks a lot,
Alex
 
N

neo [mvp outlook]

LDAP is the only other way I can think of. However the bad think about LDAP
is that you would be designing dialogs boxes and such to emulate/simulate
Outlook's address dialog box when it comes time to throw up a user interface
to the user.
 

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