none
Setting the SelectedMailingAddress to Home RRS feed

  • Question

  • I have the following code

    var person = (outlook.ContactItem)_application.CreateItem(outlook.OlItemType.olContactItem);
    
    person.FirstName = contact.FirstName;
              person.LastName = contact.LastName;
              person.JobTitle = contact.JobTitle;
              person.CompanyName = contact.CompanyName;
              person.Email1Address = contact.EmailAddress;
              person.Email2Address = contact.Email2Address;
     
              // Defaults to business as default 
              person.SelectedMailingAddress = outlook.OlMailingAddress.olNone;
       
              person.HomeAddressStreet = contact.HomeAddressStreet;
         

    How to I make the Home address the default (Business is current) when the contact form is shown?

    Friday, January 15, 2016 11:10 AM

Answers

  • Hi Darren,

    Based on my test with VBA, I found that we need to open that item through UI after the contact item has been released.

    For example:

    Dim objNS As NameSpace
    Dim objItems As Outlook.Items
    Dim person As Outlook.ContactItem
    Dim strWhere As String
    Dim objContacts As MAPIFolder
    Set objNS = Application.GetNamespace("MAPI")
    Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
    strWhere = "[Email1Address]=xing1@163.com And [Email2Address]=xing2@163.com"
    Set objItems = objContacts.Items.Restrict(strWhere)
    Set person = objItems.Item(1)
    person.SelectedMailingAddress = olBusiness
    person.Save
    Set person = Nothing
    'person.Display
    Set person = objContacts.Items.Restrict(strWhere).Item(1)
    person.Display

    For this sample, after person object released (set to Nothing), then we could open that contact manually (UI) to get the corresponding data.

    Since you are using PIA (.net), please try to release the object by using Marshal.ReleaseComObject method, then check the contact manually.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Darren Rockett Wednesday, January 20, 2016 4:12 PM
    Tuesday, January 19, 2016 4:27 AM
    Moderator

All replies

  • Hello Darren,

    Try to set the SelectedMailingAddress property to the olHome value. See OlMailingAddres for possible values. 

    Friday, January 15, 2016 12:17 PM
  • The test above was after I tried home, it does not respond to any selection
    Friday, January 15, 2016 12:21 PM
  • The Outlook object model doesn't provide any property or method for that. You can try to modify the Email1Address property of the ContactItem instead.
    Friday, January 15, 2016 1:26 PM
  • How would that help?

    Friday, January 15, 2016 1:45 PM
  • Darren,

    By default, Email1Address is used.

    person.SelectedMailingAddress = outlook.OlMailingAddress.olHome;

    Did you try to save the item (see the Save method of the ContactItem class) before displaying it to a user?

    Friday, January 15, 2016 8:28 PM
  • Yes it is saved before being displayed to the user
    Monday, January 18, 2016 9:47 AM
  • Hi Darren,

    Based on my test with VBA, I found that we need to open that item through UI after the contact item has been released.

    For example:

    Dim objNS As NameSpace
    Dim objItems As Outlook.Items
    Dim person As Outlook.ContactItem
    Dim strWhere As String
    Dim objContacts As MAPIFolder
    Set objNS = Application.GetNamespace("MAPI")
    Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
    strWhere = "[Email1Address]=xing1@163.com And [Email2Address]=xing2@163.com"
    Set objItems = objContacts.Items.Restrict(strWhere)
    Set person = objItems.Item(1)
    person.SelectedMailingAddress = olBusiness
    person.Save
    Set person = Nothing
    'person.Display
    Set person = objContacts.Items.Restrict(strWhere).Item(1)
    person.Display

    For this sample, after person object released (set to Nothing), then we could open that contact manually (UI) to get the corresponding data.

    Since you are using PIA (.net), please try to release the object by using Marshal.ReleaseComObject method, then check the contact manually.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Darren Rockett Wednesday, January 20, 2016 4:12 PM
    Tuesday, January 19, 2016 4:27 AM
    Moderator