Results 1 to 8 of 8
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Outlook Contact list question

    I'm cross posting (in fact, reposting too) in the hope that somebody--anybody[img]/w3timages/icons/sad.gif[/img] might have some tip for me here. So, pardon the redundancy if you've already encountered this...

    How do get the items of a public folder contact list into a VBA array? I'd like to filter the list too, preferably on the server side, that is, as I populate the array. It would also be nice to be able to indicate which properties (contact fields) go into the array. Can anyone help me out? Thanks much.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook Contact list question

    Assuming you have the Outlook.application open and have identified the folder where the contacts are you need:
    intContactCount = objOLFolder.items.count
    objOLFolder.GetFirst
    for x = 1 to intContactCount
    strArray(x,1) = objOLItem.(<insertContactFieldname>)
    strArray(x,2) = objOLItem.(<insertContactFieldname>)
    so on...
    objOLFolder.GetNext
    next x

    this should do it, with a bit of syntax checking !!!

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook Contact list question

    Jonathan,

    If you could provide some of that syntax, I would be most appreciative. That's where I'm having the trouble. For instance, how do you reference the fields on the contact "item"?

    strArray(x,1) = aItems.("<PR_SURNAME>")????


    Those parens are certainly non-starters.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Outlook Contact list question

    Good advice, Bart. Helen's samples are useful and also educational when you start taking them apart.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook Contact list question

    *** Geoff W URL markup added ***
    Kevin,

    Take a look at Helen Fedema's site: <A HREF="http://www.helenfeddema.com/CodeSamples.ht" target="_blank">mhttp://www.helenfeddema.com/CodeSamples.htm[/rul]
    She has some great code samples on how to connect to Outlook from Access.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook Contact list question

    Thanks Bart,

    I think I discovered, via the ol' "gum shoe" method, how to do this, but I'll take a look at this code as well. There's always a better way!

    Here's what I can up with so far:
    <pre>Sub Test2()
    Dim ol As Outlook.Application
    Dim olns As Outlook.NameSpace
    Dim numitems As Long
    Dim aItems As Outlook.Items
    Dim cItem As Outlook.ContactItem
    Dim i As Long
    Dim aFolder As Outlook.MAPIFolder
    Dim strArray() As String

    Set ol = New Outlook.Application
    Set olns = ol.GetNamespace("MAPI")
    Set aFolder = olns.Folders("Public Folders").Folders("All Public Folders").Folders("Shared").Folders("Group Contacts")
    Set aItems = aFolder.Items
    i = 0
    numitems = aFolder.Items.Count
    Debug.Print numitems
    ReDim strArray(2, numitems)

    For Each cItem In aItems
    'Debug.Print cItem.LastName
    If cItem.LastName <> "" And cItem.BusinessAddress <> "" Then
    Debug.Print cItem.LastName + ", " + cItem.FirstName
    Debug.Print cItem.BusinessAddress
    strArray(1, i) = cItem.LastName + ", " + cItem.FirstName
    strArray(2, i) = cItem.BusinessAddress
    End If
    i = i + 1
    Next

    End Sub
    </pre>


    I assigned the array to the combo yet, but that's one line.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Outlook Contact list question

    Hi Kevin,
    This is just a thought but I've always been led to believe that it's quicker to use With and End With than to repeatedly refer to an object (i.e. cItem in this case)
    Probably not noticeable unless you have a lot of contacts in the folder.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook Contact list question

    Yes, that's a good point. I'll use With when I'm done with the debugging. Thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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