Well here it is in case you can use CDO. If you did a full install of Outlook it should be installed already. If not you can install it from the Outlook CD. Its Microsoft Collaboration Data Objects 1.21.

For client applications, you must install Outlook in order to install CDO. In Outlook 2000 and later versions, CDO is included with Outlook but is not part of the default setup, nor will it install on first run. Therefore, you must explicitly select it during a custom setup or use the Windows Installer object library to programmatically install CDO


VB 6 Code Example:

VB Code:
  1. Option Explicit
  2. 'Add reference to MS CDO 1.21 Library
  3. 'Add reference to MS Office Outlook xx.x Object Library
  4. 'Add listview control (lvwGAL) 'Project > Components > MS Windows Common Controls 6.0
  5. 'Add 2 command buttons (cmdClose) and (cmdRefresh)
  6. Private moApp As Outlook.Application
  7. Private moNS As Outlook.NameSpace
  8. Private moCDO As MAPI.Session
  9.  
  10. Private Const cdoPR_DISPLAY_NAME As Long = &H3001001E
  11. Private Const cdoPR_ACCOUNT As Long = &H3A00001E
  12. Private Const cdoPR_GIVEN_NAME As Long = &H3A06001E
  13. Private Const cdoPR_SURNAME As Long = &H3A11001E
  14. Private Const cdoPR_EMAIL As Long = &H39FE001E
  15.  
  16. Private Sub cmdClose_Click()
  17.     Unload Me
  18. End Sub
  19.  
  20. Private Sub cmdRefresh_Click()
  21.     GetAddressCDO
  22. End Sub
  23.  
  24. Private Sub Form_Load()
  25.    
  26.     On Error GoTo No_Bugs
  27.    
  28.     'INITIALIZE OOM (JUST SO CDO CAN LOGON TO INSTANCE)
  29.     Set moApp = GetObject(, "Outlook.Application")
  30.     If TypeName(moApp) = "Nothing" Then
  31.         Set moApp = New Outlook.Application
  32.     End If
  33.     Set moNS = moApp.GetNamespace("MAPI")
  34.     'INITIALIZE CDO
  35.     Set moCDO = CreateObject("MAPI.Session")
  36.     moCDO.Logon "", "", False, False
  37.     'INITIALIZE LISTVIEW
  38.     With lvwGAL
  39.         .FullRowSelect = True
  40.         .LabelEdit = lvwManual
  41.         .MultiSelect = False
  42.         .View = lvwReport
  43.         .ColumnHeaders.Add , , "", 0
  44.         .ColumnHeaders.Add , , "Display Name", (.Width / 5) - 70
  45.         .ColumnHeaders.Add , , "Last Name", (.Width / 5) - 70
  46.         .ColumnHeaders.Add , , "First Name", (.Width / 5) - 70
  47.         .ColumnHeaders.Add , , "Alias", (.Width / 5) - 70
  48.         .ColumnHeaders.Add , , "E-Mail", (.Width / 5) - 70
  49.         .Sorted = True
  50.         .SortOrder = lvwAscending
  51.         .SortKey = 1
  52.     End With
  53.     'POPULATE LISTVIEW
  54.     GetAddressCDO
  55.     Exit Sub
  56.    
  57. No_Bugs:
  58.     If Err.Number = 429 Then
  59.         Resume Next
  60.     Else
  61.         MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
  62.     End If
  63. End Sub
  64.  
  65. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  66.     moCDO.Logoff
  67.     Set moCDO = Nothing
  68.     Set moNS = Nothing
  69.     Set moApp = Nothing
  70. End Sub
  71.  
  72. Private Sub lvwGAL_DblClick()
  73.     On Error Resume Next
  74.     Dim oDetails As Object
  75.     Set oDetails = moCDO.GetAddressEntry(lvwGAL.SelectedItem)
  76.     oDetails.Details
  77.     Set oDetails = Nothing
  78. End Sub
  79.  
  80. Private Sub GetAddressCDO()
  81.  
  82.     On Error GoTo No_Bugs
  83.    
  84.     Dim oAEntries As Object
  85.     Dim oAEntry As Object
  86.     Dim oFields As Object
  87.     Dim lvItm As ListItem
  88.     Dim i As Integer
  89.     Dim ii As Integer
  90.     Dim iii As Integer
  91.     Dim vDetails As Variant
  92.     Dim lRet As Long
  93.    
  94.     lvwGAL.ListItems.Clear
  95.     Set oAEntries = moCDO.AddressLists.Item("Global Address List").AddressEntries
  96.     For i = 1 To oAEntries.Count
  97.         Set oAEntry = oAEntries.Item(i)
  98.         Set lvItm = lvwGAL.ListItems.Add(, , oAEntry.ID)
  99.         'ITERATE THROUGH ALL FIELDS OF THIS ADDRESS ENTRY
  100.         For ii = 1 To oAEntry.Fields.Count
  101.             Set oFields = oAEntry.Fields(ii)
  102.             vDetails = oFields.Value
  103.             On Error Resume Next
  104.             lRet = UBound(vDetails)
  105.             If Err.Number = 0 Then
  106.                 'ITERATE THROUGH ALL VALUES FOR THIS ARRAY
  107.                 For iii = 0 To UBound(vDetails)
  108.                     'Debug.Print "Field ID:  " & oFields.ID & "; Field Array #" & iii & ";Value:  " & vDetails(iii)
  109.                 Next
  110.             Else
  111.                 'ADD SINGLE VALUES TO THE LISTVIEW
  112.                 If oFields.ID = cdoPR_DISPLAY_NAME Then
  113.                     lvItm.SubItems(1) = vDetails
  114.                 ElseIf oFields.ID = cdoPR_SURNAME Then
  115.                     lvItm.SubItems(2) = vDetails
  116.                 ElseIf oFields.ID = cdoPR_GIVEN_NAME Then
  117.                     lvItm.SubItems(3) = vDetails
  118.                 ElseIf oFields.ID = cdoPR_ACCOUNT Then
  119.                     lvItm.SubItems(4) = vDetails
  120.                 ElseIf oFields.ID = cdoPR_EMAIL Then
  121.                     lvItm.SubItems(5) = vDetails
  122.                 End If
  123.                 'Debug.Print "Field ID:  " & oFields.ID & "; Value  " & vDetails
  124.             End If
  125.         Next
  126.         Set lvItm = Nothing
  127.     Next
  128.     Set oAEntries = Nothing
  129.     Set oAEntry = Nothing
  130.     Set oFields = Nothing
  131.     Exit Sub
  132.    
  133. No_Bugs:
  134.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
  135. End Sub