none
Outlook form SelectNamesDialog InitialAddressList RRS feed

  • Question

  • I am trying to set the initial address list in an outlook form for a select names dialog...

    When I set the initialaddresslist, I just get 'The Opteration Failed'.  It doesn't matter if I use the GAL or a local list, any list gives the same response. 

    Any Ideas?

    Sub btnAdd_click()
       Set Page = Item.GetInspector.ModifiedFormPages("Deloitte DBriefs")
       Set olns = Item.Application.GetNameSpace("MAPI")
       Set Control = Page.Controls("ListBox2")

       Set myAddressList = olns.AddressLists("Contacts") 
       Set oContacts = olns.GetDefaultFolder(10)
       Set oContactsAdd = olNS.GetGlobalAddressList
       Set oDialog = olns.GetSelectNamesDialog
       With oDialog
    .InitialAddressList = oContactsAdd
    .SetDefaultDisplayMode(6)
    .ForceResolution = false
    .Caption = "Select contacts to add to the dBrief Form"
    .ToLabel = "Select contacts"
    .NumberOfRecipientSelectors = 1
    If .Display Then
    For Each olRecipient In .Recipients
    Set oAddEn = olRecipient.AddressEntry
    If oAddEn.AddressEntryUserType = olExchangeUserAddressEntry Or oAddEn.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then 
      Set itm = oAddEn.GetExchangeUser 
    Else 
    Set itm = oAddEn.GetContact 
    End If 
    Item.Links.Add itm
    Next
    End If
       End With
    End Sub

    Friday, September 21, 2012 2:59 PM

All replies

  • Try this code in the Outlook VBA project and see if it works for you in showing the Contacts folder contents:
     
    Sub ShowOnlyContacts()
        Dim oDialog As SelectNamesDialog
        Set oDialog = Application.Session.GetSelectNamesDialog
        
        Dim oAL As AddressList
        Set oAL = Application.Session.AddressLists("Contacts")

        oDialog.InitialAddressList = oAL
        oDialog.Display
    End Sub

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "brmathews" <=?utf-8?B?YnJtYXRoZXdz?=> wrote in message news:bc7ec24d-9707-42e3-99c0-99cfb3a72606...

    I am trying to set the initial address list in an outlook form for a select names dialog...

    When I set the initialaddresslist, I just get 'The Opteration Failed'.  It doesn't matter if I use the GAL or a local list, any list gives the same response. 

    Any Ideas?

    Sub btnAdd_click()
       Set Page = Item.GetInspector.ModifiedFormPages("Deloitte DBriefs")
       Set olns = Item.Application.GetNameSpace("MAPI")
       Set Control = Page.Controls("ListBox2")

       Set myAddressList = olns.AddressLists("Contacts") 
       Set oContacts = olns.GetDefaultFolder(10)
       Set oContactsAdd = olNS.GetGlobalAddressList
       Set oDialog = olns.GetSelectNamesDialog
       With oDialog
    .InitialAddressList = oContactsAdd
    .SetDefaultDisplayMode(6)
    .ForceResolution = false
    .Caption = "Select contacts to add to the dBrief Form"
    .ToLabel = "Select contacts"
    .NumberOfRecipientSelectors = 1
    If .Display Then
    For Each olRecipient In ..Recipients
    Set oAddEn = olRecipient.AddressEntry
    If oAddEn.AddressEntryUserType = olExchangeUserAddressEntry Or oAddEn.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then 
      Set itm = oAddEn.GetExchangeUser 
    Else 
    Set itm = oAddEn.GetContact 
    End If 
    Item.Links.Add itm
    Next
    End If
       End With
    End Sub


    Ken Slovak MVP - Outlook
    Friday, September 21, 2012 5:35 PM
    Moderator
  • Yes that works in VBA but not in the outlook custom forms.  

    I know the custom forms are a little different (VBScript vs VBA).

    I had to modify the code slightly but still get 'Operation Failed' on the bold line. 

    Sub ShowOnlyContacts()
        Set oDialog = Application.Session.GetSelectNamesDialog
        
        Set oAL = Application.Session.AddressLists("Contacts")

        oDialog.InitialAddressList = oAL
        oDialog.Display
    End Sub

    Monday, September 24, 2012 12:38 PM
  • Can you either step your code in the form or put tests in there to see if oAL Is Nothing? That's about the only way I can see the code failing, assuming you're running on an Outlook version that supports the SelectNamesDialog. Otherwise, you aren't running in a non-English version of Outlook, are you?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "brmathews" <=?utf-8?B?YnJtYXRoZXdz?=> wrote in message news:7e9d582f-def2-420f-9586-7571ed790bba...

    Yes that works in VBA but not in the outlook custom forms.  

    I know the custom forms are a little different (VBScript vs VBA).

    I had to modify the code slightly but still get 'Operation Failed' on the bold line. 

    Sub ShowOnlyContacts()
        Set oDialog = Application.Session.GetSelectNamesDialog
        
        Set oAL = Application.Session.AddressLists("Contacts")

        oDialog.InitialAddressList = oAL
        oDialog.Display
    End Sub


    Ken Slovak MVP - Outlook
    Monday, September 24, 2012 3:35 PM
    Moderator