Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Outlook Address Book.

Status
Not open for further replies.

gazal

Programmer
Apr 30, 2003
212
0
0
OM
Hi Friends

I have found many codes on internet to Read the Address Book from Outlook.

But all those code Read the address book which is stored on the Local Machine, where as we use Exchange Server 5.5, and all our addresses are stored on the Server, And the list is called as "Global Address List", So can someone tell me how can i retrieve the addresses stored on the Server....

Please help me...

Regards & Thanks

Gazal
 
Search for 'Exchange Server 5.5' up the top under forums. There are two forums, if you post in there your more likely to get an answer.

Make sure your questions are in the right forum.

-Niphyr

------------------------------
------------------------------
 
I created a form with 3 boxes EMail, Text5, Text7 (forgive the naming conventions). I then use the two subs below to read the address book and populate the form. Our global address book is on the server, however this has no trouble reading it from the local machine. You must also have a reference for Microsoft Outlook ##.# Object Library. I had this working with access 97, have not tried it with anything newer.

Code:
Private Sub Form_Activate()
Dim objSession As MAPI.Session
Dim collAddressLists As AddressLists
Dim objAddressList As AddressList
Dim collAddressEntries As AddressEntries

Set objSession = CreateObject("MAPI.Session")
    objSession.Logon ("MS Exchange Settings")
Set collAddressLists = objSession.AddressLists
For Each objAddressList In collAddressLists
    'Debug.Print objAddressList.Name,
    'Debug.Print objAddressList.Index,
    'Debug.Print objAddressList.IsReadOnly,
    Set collAddressEntries = objAddressList.AddressEntries
    'Debug.Print str(collAddressEntries.Count)
    Next objAddressList
Set collAddressEntries = objSession.AddressLists("Global Address List").AddressEntries
    WalkAddressList collAddressEntries
    objSession.Logoff

End Sub

Sub WalkAddressList(collAddressEntries As AddressEntries)
Dim objaddressEntry As AddressEntry

For Each objaddressEntry In collAddressEntries
    Me.EMail = objaddressEntry.Name
    Me.Text5 = Right(objaddressEntry.Name, 3)
    Me.Text7 = Left(objaddressEntry.Name, 6)
    DoCmd.GoToRecord acDataForm, "EMailList", acNext
    Next objaddressEntry
End Sub

The hardest questions always have the easiest answers.
 
Thanks jtMatch

Your code seems fine, but didnt work for me, as it said cant find user defined type of Mapi.Session, anyways my work is done with the following code, found on Tek-Tips only...

But now in this i want to Seperate First, Last Name and Email ID's how do i do that????

Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myAddresslist As Outlook.AddressList
Dim myAddressentry As Outlook.AddressEntry

Dim myCounter As Long
myCounter = 1

Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myAddresslist = myNamespace.AddressLists("Global Address List")
For Each myAddressentry In myAddresslist.AddressEntries
Set myAddressentry = myAddresslist.AddressEntries(myCounter)
vForm.vList.AddItem myAddressentry
Set myAddressentry = Nothing
myCounter = myCounter + 1
Next
myOlApp.Quit
Set myOlApp = Nothing

Regards

Gazal
 
To use the MAPI bits, you need to add the MS MAPI controls 6.0 to your project. They are in MSMAPI32.OCX

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
gazal,

Check out thread222-782555 it may be of use.

Everybody body is somebodys Nutter.
 
hi thanks for ur responses

I got it working but a few more questions.

1. Its very Slow, where as if i goto outlook and click on Address Book it displays the complete list in a falsh, where as its taking minimum, 2-3 minutes to show it in VB.

2. The Outlook Security Pop Up keeps coming, asking for permission for 1 minute, 5 minute or 10 minutes how do i avoid this...

3. and How if i want to get only First and Last Names???

Please guide

Gazal
 
>how do i avoid this...

Check out a library called Redemption...
 
where can i get that library and what it does???

What about the first and last name issues????

Gazal
 
Keyword search on this forum for Redemption - it's been covered frequently

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top