Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Don't want to resolve addresses in Outlook (Office 2003)

    I'm having VBA code (in Excel) which allows me to read Outlook distribution lists from our Exchange server and display (again in Excel) the members. Now it's a bit customized but things work. There is however one problem. If there is e.g. a DL called "ABC" and there is a DL called "ABCD" and I request my tool to process "ABC" I get an error bascally indicating Outlook cannot resolve the reference (as by providing "ABC" as name, I could also mean "ABCD").
    The "solution" for this is to do a "Resolve" method (which works), disadvantage of that one is that this will bring up an Outlook dialog box prompting the user to manually select the DL to process. What I really want is that this is not required, in other words: how do I tell the code that when I provide "ABC" as name, I really mean "ABC" and not "ABCD" or anything else that matches this?? So it should use the name, not try to make more out of it.

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    I don't know the solution, but I admire the problem. Could you post the section of code that accesses the DistList and causes the resolve dialog?
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    At the point where you learn that there is a distribution list, can you create an object reference or store a unique identifier so that you do not need to search for the DL by name at all?

  4. #4
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    Here's an extracted piece of code:

    <pre><font color=blue>
    On Error GoTo NoMAPI
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon ShowDialog:=False, NewSession:=False
    '
    Set objUser = objSession.CurrentUser ' Get current user
    ' Create new message and set DL
    Set objNewMessage = objSession.Outbox.Messages.Add
    Set objNewRecip = objNewMessage.Recipients.Add
    objNewRecip.Name = MainDL
    ' Resolve address against the Exchange Directory
    ''objNewRecip.Resolve
    ' Set Distribution List and get members
    Set objDistributionList = objNewRecip.AddressEntry
    Set objMembers = objDistributionList.Members
    ' Loop through the members
    On Error Resume Next
    For Each objmember In objMembers
    '
    'UID
    UID= objmember.Fields(CdoPR_ACCOUNT).Value
    'First Name
    FN = objmember.Fields(CdoPR_GIVEN_NAME).Value
    </pre>

    </font color=blue>

  5. #5
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    I'm not sure if that works (and if I would, I wouldn't know how to do this). Basically in an earlier part of my code I already make the user choose a DL and validate that. In the code snippet I just posted, you can see me taking the DL_Name and process that further. I have commented out the "Resolve" step, but as said, that generates errors when the name can be resolved into more than one possibility (it does work of course if the given name is unique)

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    What is the code to set MainDL?

  7. #7
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    Basically, I prompt for a DL name (or part of that) in a first input dialog (the given name is stored in "DL_Nam"). In the (stripped; I also deleted some error traps) code below, I am taking that name and list all possible DL-names that match into a Combobox that I then use in the next user dialog. There the user can select the final DL from the drop-down.
    To continue with the example I gave in my first post: let's suppose we have the following DLs existing "A" "AB" ABC" and "ABCD". Now let's say that in the first dialog, I have typed "AB"; the combobox below will now show all DLs that match: "AB", "ABC" and "ABCD". Now from this drop-down, I select "ABC" as my final DL and that is fed into the code I posted earlier. This time, I made my selection: I want "ABC" and not something else. Still, in the code when I process and not resolve, I again get the matching options "ABC" and "ABCD". As said; I have made my choice in the dropdown already and now do not want matching DLs anymore but the exact match.
    Just a thought: what would happen if I'd end the "ABC" string with a Char(0)???

    <pre><font color=blue>
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon ShowDialog:=False, NewSession:=False
    '
    Set objAddressList = objSession.AddressLists("Global Address List")
    Set objAddressEntries = objAddressList.AddressEntries
    '
    Set objAEFilt = objAddressEntries.Filter ' original empty default filter
    '
    objAEFilt.Name = DL_Nam ' string used in a name resolution search
    '
    Cnt = objAddressEntries.Count
    '
    UserForm2.ComboBox1.Clear
    For Each objAddressEntry In objAddressEntries ' loops and Sets each objAddressEntry
    UserForm2.ComboBox1.AddItem objAddressEntry.Name
    Next
    '
    objAddressEntries.Filter = Nothing ' invalidates and clears filter
    Set objAEFilt = objAddressEntries.Filter ' new empty filter
    Set objAddressEntries = Nothing
    Set objAddressEntry = Nothing
    objSession.Logoff
    </pre>

    </font color=blue>

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    Okay, since you are closing the collection before you show the form, this is going to be a bit more challenging. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Each objAddressEntry has a unique ID, objAddressEntry.ID. You need to capture this ID, it's a string. You can do this either by leaving the collection open and using the listbox index to access the correct element into the collection, or you can store the Name and ID in an array as you build the listbox, or you can add the long string into the listbox data, preceding it with a lot of spaces so the users don't see it, and then a delimiter (such as a vertical bar) that will make it easy to access the data -- e.g.:

    <code>strDLuniqueID = Split(listboxitemvalue, "|")(1)</code>

    Once you have your ID, then you can retrieve the DL by changing this:

    <code>objNewRecip.Name = MainDL</code>

    to this:

    <code>objNewRecip.ID = strDLuniqueID</code>

    Now... since it was very difficult to test your code fragments in isolation, I may be wrong that ID is unique, and if so, that would be a big problem, but it worked in my little test and I suspect it really is. Hope this helps.

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    To the best of my limited knowledge, outlook Item ID is unique.
    -John ... I float in liquid gardens
    UTC -7ąDS

  10. #10
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't want to resolve addresses in Outlook (Office 2003)

    Yes, that works. I must admit that it was some work to 'weave' it into my code (also as the code traverses down and processes upto 4 additional levels of DL in the orginal DL) but yes, the ID is unique.

    What I ended up doing is put the code I used to populate the combobox in a separate routine (function) and changing it so it would loop over all the members until an exact match was found; it would then return the ID.

    Here's the code:
    <pre><font color=blue>
    Private Function Get_Unique_ID(DL_Name As String) As String
    Dim strProfile As String
    '
    Dim objSession As MAPI.Session
    Dim objAddressEntry As MAPI.AddressEntry
    Dim objAddressEntries As MAPI.AddressEntries
    Dim objAEFilt As AddressEntryFilter
    Dim objAddressList
    '
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon ShowDialog:=False, NewSession:=False
    '
    Set objAddressList = objSession.AddressLists("Global Address List")
    Set objAddressEntries = objAddressList.AddressEntries
    '
    Set objAEFilt = objAddressEntries.Filter ' original empty default filter
    '
    objAEFilt.Name = DL_Nam ' string used in a name resolution search
    '
    For Each objAddressEntry In objAddressEntries
    If DL_Name = objAddressEntry.Name Then
    Get_Unique_ID = objAddressEntry.ID
    Exit For
    Next
    '
    objAddressEntries.Filter = Nothing ' invalidates and clears filter
    Set objAEFilt = objAddressEntries.Filter ' new empty filter
    Set objAEFilt = Nothing
    Set objAddressEntries = Nothing
    Set objAddressEntry = Nothing
    objSession.Logoff
    Set objAddressList = Nothing
    Set objSession = Nothing
    End Function
    </pre>

    </font color=blue>

Posting Permissions

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