General discussion

Locked

Bind A MAPI session with Outlook from VB

By mnm82 ·
I am attempting to query a Microsoft Outlook Global Address Book to obtain previously stored personal details into a Visual Basic 6 application but cannot establish a session connection or bind a "MAPI.Session" to Outlook. Have also tried early binding via the Outlook 9.0 library reference but in vain. Could someone shed some light or a ray of hope all I need to retrieve is Names, Adress, Telephone No. Email addrs and the like. Please assist

This conversation is currently closed to new comments.

13 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Bind A MAPI session with Outlook from VB

by fofa In reply to Bind A MAPI session with ...

One of the drivers that came with something (office/VB/some MS product) contained an ODBC driver for Exchange database, that is what I use to gain access to this information.

Collapse -

Bind A MAPI session with Outlook from VB

by mnm82 In reply to Bind A MAPI session with ...

Thanks for the Exchange ODBC suggestion but this adds a complexity I should not pursue at moment given project time-scale.
I have downloaded some examples that use Collaborative Data Objects CDO but cannot bind to some objects/methods to the underlining cdo.dll. I get Runtime error '429' ActiveX Component can't create object. Mind you this cdo.dll (ver 1.2) was not listed in the VB references and I had to browse to find it. Also, regsvr32 of cdo.dll failed with error 'LoadLibrary.....failed. - The specified module could not be found'. Guy and Gals I still need you r assistance. Please YELP!

Collapse -

Bind A MAPI session with Outlook from VB

by Peyison In reply to Bind A MAPI session with ...

There are two sets of objects that contain address/contact information. The first is the Address Book, but you can only get Name and Email address (from what I can tell). Here's how that would work:

(you need to have a reference to the Outlook 9.0 Library)

Dim oNameSpace As Outlook.NameSpace
Dim oAddList As Outlook.AddressList
Dim oEntry As Outlook.AddressEntry

Set oNameSpace = Application.GetNamespace("MAPI")

For Each oAddList In oNameSpace.AddressLists
For Each oEntry In oAddList.AddressEntries
MsgBox oAddList.Name & " " & oEntry.Name & " " & oEntry.Address
'This pops up a details window
oEntry.Details
Next
Next


The other way is to use Contacts. From what I can tell this is the same info that appears in the Address List info, but I'm not sure how it works if you're running on an Exchange Server. You might not have info from your Global Address Book in your contact list. Here's how this works:

Dim oNameSpace As Outlook.NameSpace
Dim oContact As Outlook.ContactItem
Dim oFolder As Outlook.MAPIFolder


Set oNameSpace = Application.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(olFolderContacts)

For Each oContact In oFolder.Items
With oContact
MsgBox .FirstName & " " & .LastName & " " & .BusinessAddress & " " & .BusinessTelephoneNumber
End With
Next

Once you get this running, you should be able to play around in Help to get all the properties you need.

Hope this helps.

Collapse -

Bind A MAPI session with Outlook from VB

by Shanghai Sam In reply to Bind A MAPI session with ...

Thanks dor the response and suggestion. As a stop gap I have gone for the suggestion to copy Global Address List to Outlook Contacts. This progressed fine and can get all address entries (without Telephone details, Email etc..) if don't reference oContact.FirstName otherwise 'am getting a runtime error '13' type mismatch.

The working Code snippet is hereafter pasted.

Dim oNameSpace As Outlook.NameSpace
'Dim oContact As Outlook.ContactItem
Dim oContact As Variant
Dim oFolder As Outlook.MAPIFolder

Set oNameSpace = Application.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(olFolderContacts)
oFolder.Display


For Each oContact In oFolder.Items
'With oContact
'MsgBox .FirstName & " " & .LastName & " " & .BusinessAddress & " " & .BusinessTelephoneNumber
Debug.Print oContact
'End With
Next

By the way VB protests if you call a msgbox within an With ...End With construct.

I still need some more more delta help. We shall get there!!!

Collapse -

Bind A MAPI session with Outlook from VB

by Peyison In reply to Bind A MAPI session with ...

The code worked fine for me, including the call to msgbox. There is no restriction in VB for calling msgbox within a With - End With clause.

Collapse -

Bind A MAPI session with Outlook from VB

by mnm82 In reply to Bind A MAPI session with ...

Poster rated this answer

Collapse -

Bind A MAPI session with Outlook from VB

by Limbo In reply to Bind A MAPI session with ...

/Me backs up Peyison

And I once programmed POP-11 dontchaknow!!

Collapse -

Bind A MAPI session with Outlook from VB

by mnm82 In reply to Bind A MAPI session with ...

Poster rated this answer

Collapse -

Bind A MAPI session with Outlook from VB

by Limbo In reply to Bind A MAPI session with ...

Err... USER DELETED!!!

You've asked over 280 questions and have a 100% unrated score!!!

100% !!!!?

Isn't that a slightly cheeky! And a liberty (to say the least) to take so much from such a valuable resource without giving anything back?

Collapse -

Bind A MAPI session with Outlook from VB

by mnm82 In reply to Bind A MAPI session with ...

I dont follow your line of reasoning concerning tech points. I suppose if a user is unintentionally deleted then user "UserDeleted" earns those points. I can rest assure you Limbo that my Tech points are a humble 735. So if you want points discussion use another resource. But you profile and contribution is very respectiveful. Please keep it that way. Thanks all the same.

Back to Web Development Forum
13 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums