Working with Data: The NameSpace Object

[Previous] [Next]

You learned in the preceding section that by using the NameSpace object, you can access the AddressLists collection. The AddressLists collection contains all of the different places where the addresses of users can reside. Through this collection, you can access individual AddressList objects, which are the actual address books. The methods and properties of the AddressLists collection that you should be interested in are the Count property and the Item method. As you would expect, the Count property returns the number of AddressList objects in the collection, and the Item method allows you to access individual AddressList objects. Most times the AddressList object that your application will access will be either the user's personal address book or the Exchange Server Global Address List. Figure C-5 shows you a list of available AddressLists in the Outlook client.

click to view at full size.

Figure C-5 The Outlook Address Book viewer showing a list of available address books, or AddressList objects.

The following example shows you how to scroll through the AddressList objects by using the Count property and Item method, and how to retrieve specific AddressList objects by using their names:

     Sub CommandButton1_Click         On Error Resume Next         set oNS = Application.GetNameSpace("MAPI")         set oALs = oNS.AddressLists         for i = 1 to oALs.Count             msgbox oALs.Item(i).Name         next         'The Exchange Server GAL can be available both online and offline         set oGAL = oALs("Global Address List")         if oGAL is Nothing then             set oGAL = oALs("Global Address List (Offline)")         end if         msgbox "Accessing the " & oGAL.Name & " by name."         set oPAB = oALs("Personal Address Book")         msgbox "Accessing the " & oPAB.Name & " by name."     End Sub 

AddressList Object

The AddressList object is accessed through the AddressLists collection. This object contains the AddressEntries property for attaining the actual directory entries in the AddressList. The following example shows you to how count the number of AddressEntries by using the AddressList object to access those AddressEntries:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oALs = oNS.AddressLists         set oALPAB = oALs("Personal Address Book")         intCount = oALPAB.AddressEntries.Count         msgbox "There are " & intCount & " entries in the " & oALPAB.Name     End Sub 



Programming Microsoft Outlook and Microsoft Exchange
Programming Microsoft Outlook and Microsoft Exchange, Second Edition (DV-MPS Programming)
ISBN: 0735610193
EAN: 2147483647
Year: 2000
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net