Edit a Business Contact
To edit any existing Business Contact object programmatically, do the following:
- Select the object.
- Assign new values to those properties that you want to modify.
- Invoke the Save method on the object to save the changes.
The following C# and Visual Basic for Applications (VBA) examples show how to select a Business Contact object.
C#
private void EditBusinessContact()
{
Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
Outlook.Application olApp = (Outlook.Application)_app;
Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
Outlook.Folders folders = olNameSpace.Session.Folders;
Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"];
Outlook.Folder contactsFolder = (Outlook.Folder)bcmRootFolder.Folders["Business Contacts"];
string strQuery = "[FileAs] = 'John Smith'";
Outlook.ContactItem contactItem = (Outlook.ContactItem)contactsFolder.Items.Find(strQuery);
if (contactItem != null)
{
contactItem.BusinessAddressCity = "New City Address";
contactItem.BusinessAddressState = "New Address State";
contactItem.BusinessAddressStreet = "New Address Street";
contactItem.Save();
}
else
{
Console.WriteLine("Contact not found");
}
}
VBA
Sub EditBusinessContact()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim bcmRootFolder As Outlook.Folder
Dim olFolders As Outlook.Folders
Dim bcmContactsFldr As Outlook.Folder
Dim existContact As Outlook.ContactItem
Set olApp = CreateObject("Outlook.Application")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolders = objNS.Session.Folders
Set bcmRootFolder = olFolders("Business Contact Manager")
Set bcmContactsFldr = bcmRootFolder.Folders("Business Contacts")
Set existContact = bcmContactsFldr.Items.Find("[FileAs] = 'John Smith'")
If Not TypeName(existContact) = "Nothing" Then
existContact.BusinessTelephoneNumber = "(111)111-1111"
existContact.Email1Address = "someone@example.com"
existContact.Save
Else
MsgBox ("Could not find the Business Contact with Full Name John Smith")
End If
Set existContact = Nothing
Set bcmContactsFldr = Nothing
Set bcmRootFolder = Nothing
Set olFolders = Nothing
Set objNS = Nothing
Set olApp = Nothing
End Sub
See Also
Create a Business Contact | Select a Business Contact | Delete a Business Contact | 2007 Office System: Updated Developer Content