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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Global Address Books

Status
Not open for further replies.

fruityBoy

Programmer
Jul 21, 2000
51
GB
Hi, I am trying to access details from the Exchange Global Address List, without much success.

This is an example of what I am doing:

looutlook = createobject('outlook.application')
lonamespace = loooutlook.getNameSpace('mapi')
loaddressList = ;
lonameSpace.addressLists('Global Address List')

for each loaddressEntry in addressList.AddressEntries
? loAddressEntry.name
endfor

This works fine, however, I need to access the individual fields in the global address book, such as fax and email addresses, but I cannot see the way to do this.

I try to access loAddressEntry.fields using numeric and string parameters, but I get the message 'member fields does not evaluate to an object'.

I am stuck, I could try accessing the address book using the MAPI session control, or ADO maybe, but I would like to try and keep it all in Outlook.

Thanks for your help in advance.


 
Here's the example for the Add Method for the Address Entries in the Microsoft Outlook VB reference. The VFP code wouldn't be a lot different, but I don't have time just now to translate.

Code:
Sub CommandButton1_Click()
    myName = Item.To
    Set myNameSpace = Application.GetNameSpace("MAPI")
    Set myGAddressList = myNameSpace.AddressLists("Global Address List")
    Set myGEntries = myGAddressList.AddressEntries
    Set myGEntry = myGEntries(myName)
    myManager = myGEntry.Manager    
    Set myGEntry2 = myGEntries(myManager)
    Set myPAddressList = myNameSpace.AddressLists("Personal Address Book")
    Set myPEntries = myPAddressList.AddressEntries
    'Add a new AddressEntry object to the personal 
    'address collection with the name, address, and
    'manager of the name in your To field.
    Set myPEntry = myPEntries.Add("Microsoft Mail Address", myName)
    myPEntry.Address = myGEntry.Address
    myPEntry.Manager = myGentry.Manager
    'Update to persist the collection.
    myPEntry.Update
    'Now add the manager's info. to
    'the Personal address collection.
    Set myPEntry2 = myPEntries.Add("Microsoft Mail Address", myManager)
    myPEntry2.Address = myGEntry2.Address
    myPEntry2.Manager = myGentry2.Manager
    myPEntry2.Update
End Sub

It seems to me your code was mostly there. You just need to supply an index to the particular item you need.

Dave Dardinger
 
Is there a way to get the phone number and company field the same way the manager field is retrieved?

Ron
 
Well, it looks like CompanyName property is associated with a ContactItem object which you can create, for instance with:

Code:
 myOlApp = CreateObject("Outlook.Application")
myItem = myOlApp.CreateItem(olContactItem)

For phone number there are several possibilities including:

HomeTelephoneNumber
Home2TelephoneNumber
CompanyMainTelephoneNumber
BusinessTelephoneNumber
Business2TelephoneNumber
MobileTelephoneNumber
OtherTelephoneNumber

Etc. They are also properties of ContactItem objects.


Dave Dardinger
 
I was trying to get fields from the Global Address List. I was able to get what I was looking for by using CDO in VB.

Thanks.
Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top