none
VBA in Outlook.... Outlook recipient is Group Contact that is not resolving RRS feed

  • Question

  • Access and Outlook 2010 with Windows 7; the issue is occurring in Outlook.

    I use Access VBA to create draft e-mails in Outlook.  This process works perfectly.

    The Access VBA code creates an e-mail in the Drafts folder of Outlook using a Group Contact from Outlook.

    I used some code from Mr. Excel (included below; with some mods) to send the e-mails from the Drafts folder.... this works normally.... IF the problem did not exist that is associated with the reason for my post.

    The Issue

    The Group Contact in Outlook is named (for example) "ABCD WRO" and has a number of e-mail addresses.  We edit the Group Contact to add/remove recipients.  I can normally great an e-mail, type "AB" and am presented with an auto complete list of names to select. Once selected (or if I type out the full "ABCD WRO" text), the text is displayed with an underline, which states the address (Group Contact) is resolved.

    But... for the e-mails that were created via Access VBA, the "ABCD WRO" recipient is not auto-resolved and shows as plain text. I have to click on the To address in each e-mail (there is only one Group Contact per e-mail) and then click on the Check Names button and click Save.  If I do this with every e-mail, the below code works.  I might as well just send each each separately in this case.

    To be clear... the auto-resolve is not happening even if I try to send out each e-mail manually (no VBA code to send).  I have to click on Check Names and then can send the e-mail.

    The Question

    How do I auto resolve the Group Contact in my code?

    Thank you.

    Navin

    Code that sends all e-mails in my Draft folder that have a Recipient; this code in in Outlook

    Dim lDraftItem As Long

    Dim myOutlook As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolders As Outlook.Folders
    Dim myDraftsFolder As Outlook.MAPIFolder

    'Send all items in the "Drafts" folder that have a "To" address filled in.

    'Setup Outlook

    Set myOutlook = Outlook.Application
    Set myNameSpace = myOutlook.GetNamespace("MAPI")
    Set myFolders = myNameSpace.Folders

    'Set Draft Folder. This will need modification based on where it's being run.
    ' ORIGNAL: Set myDraftsFolder = myFolders("Personal Folders").Folders("Drafts")

    'Modified version to define folder
    Set myDraftsFolder = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

    'Loop through all Draft Items

    For lDraftItem = myDraftsFolder.Items.Count To 1 Step -1

    'Check for "To" address and only send if "To" is filled in.

    If Len(Trim(myDraftsFolder.Items.Item(lDraftItem).To)) > 0 Then

    'Send Item
    myDraftsFolder.Items.Item(lDraftItem).Send

    End If

    Next lDraftItem

    'Clean-up

    Set myDraftsFolder = Nothing
    Set myNameSpace = Nothing
    Set myOutlook = Nothing

    End Sub

    Thursday, April 13, 2017 12:13 PM

Answers

  • Hello,

    You can use the ResolveAll method of the Recipients class which attempts to resolve all the Recipient objects in the Recipients collection against the Address Book.

    'Loop through all Draft Items For lDraftItem = myDraftsFolder.Items.Count To 1 Step -1 If myDraftsFolder.Items.Item(lDraftItem).Recipients.ResolveAll Then 'Send Item myDraftsFolder.Items.Item(lDraftItem).Send End If Next lDraftItem



    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Monday, April 17, 2017 2:39 PM

All replies