Results 1 to 7 of 7

Thread: [RESOLVED] Access Contacts in a Public Folder?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Resolved [RESOLVED] Access Contacts in a Public Folder?

    Hi,

    I started working with VBA about a month ago. I come from a non-Microsoft background (Java, JSP) so I was not familiar with Microsoft's APIs, and at this point I have barely scratched the surface.

    I'm currently working on an Microsoft Access 2003 application that needs to access contact information stored in an Outlook 2003 public folder.

    I have used CDO to access the global and personal contact lists successfully. However, the contacts I need to access are several subfolders deep in Public Folders. First of all, is it possible to access this contact list with CDO? Secondly, can you point me to a tutorial that will at least explain the basics of how to do so?

    Thanks!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access Contacts in a Public Folder?

    Welcome to the Forums.

    I dont use CDO that much but I can do it with the Outlook Object Model.

    You need to recursively navigate down the folder structure to the destination folder. Just like you do with local private folders. Just use the "Public Folders" and then "All Public Folders". Then keep going down each folder level until you get to the desired folder.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Re: Access Contacts in a Public Folder?

    Thanks! Having an API to research helps a lot. I'll post the code I came up with soon.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access Contacts in a Public Folder?

    I'll save you some time, but I dont have Exchange available right now so this is from memory.
    VB Code:
    1. Private Sub GetPublicContacts()
    2.     Dim oApp As Outlook.Application
    3.     Dim oFolder As Outlook.MAPIFolder
    4.     Dim oItems As Outlook.Items
    5.     Dim i As Integer
    6.     Set oApp = Application
    7.     Set oFolder = oApp.GetNamespace("MAPI").Folders("Public Folders").Folders("All Public Folders").Folders("SomePublicFolder")
    8.     Set oItems = oFolder.Items
    9.     'Assumes all items are ContactItems
    10.     For i = 1 To oItems.Count
    11.         MsgBox oItems.Item(i).FullName
    12.     Next
    13.     Set oItems = Nothing
    14.     Set oFolder = Nothing
    15.     Set oApp = Nothing
    16. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Re: Access Contacts in a Public Folder?

    Thanks! That's more or less exactly what I did. I just populated a list box with some of the information from the contacts.

    At what point does this method take a noticible performance hit? 100 contacts? 1000?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Access Contacts in a Public Folder?

    Anytime you iterate through an Outlook collection it will be a performance drain. It will also depend on your network, server, and workstation performance.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Re: Access Contacts in a Public Folder?

    Here is the code (lv_Profile_List is a MS Common Controls 6.0 ListView):

    VB Code:
    1. Private Sub GetDataFromOutlook()
    2.     On Error GoTo Catch
    3.    
    4.     ' Clear the ListView Control
    5.     lv_Profile_List.ListItems.Clear
    6.  
    7.     ' Variables
    8.     Dim oFolder As mapiFolder
    9.     Dim profileItems As Items
    10.     Dim cnt As Integer
    11.     Dim lvItm As ListItem
    12.    
    13.     ' Get to the folder containing the profiles
    14.     Set oFolder = getProfileFolder()
    15.  
    16.     ' Get the first profile and prepare to iterate through the Items list
    17.     Set profileItems = oFolder.Items
    18.    
    19.     ' Run through the list and populate the ListView Control
    20.     For cnt = 1 To profileItems.Count
    21.         Set lvItm = lv_Profile_List.ListItems.Add(, , cnt)
    22.        
    23.         lvItm.SubItems(1) = profileItems.Item(cnt).FullName
    24.         lvItm.SubItems(2) = profileItems.Item(cnt).BusinessTelephoneNumber
    25.         lvItm.SubItems(3) = profileItems.Item(cnt).BusinessFaxNumber
    26.         lvItm.SubItems(4) = profileItems.Item(cnt).BusinessAddressCity
    27.         lvItm.SubItems(5) = profileItems.Item(cnt).BusinessAddressState
    28.        
    29.         Set lvItm = Nothing
    30.     Next cnt
    31.    
    32.     Exit Sub
    33.    
    34. Catch:
    35.     If Err.Number = 91 Then
    36.         Resume Next
    37.     Else
    38.         MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
    39.     End If
    40. End Sub
    41.  
    42. Private Function getProfileFolder() As mapiFolder
    43.     Dim profFolder As mapiFolder
    44.     Set profFolder = moNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
    45.     Set profFolder = profFolder.Folders("A Deeper Folder")
    46.     Set profFolder = profFolder.Folders("The Contact Items Folder")
    47.    
    48.     Set getProfileFolder = profFolder
    49. End Function

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width