Unlink Business Contacts from an Account
To unlink one or more Business Contacts from an Account object, first set the Parent Entity EntryID property of the Business Contact to an empty String. The following C# and Visual Basic for Applications (VBA) examples show how to unlink a Business Contact from an Account object.
C#
private void UnlinkContactToAccount()
{
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.UserProperty userProp;
Outlook.Folder accounts = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];
Outlook.ContactItem newAccount = (Outlook.ContactItem)accounts.Items.Add("IPM.Contact.BCM.Account");
newAccount.FullName = "Sara Hettich";
newAccount.FileAs = "Sara";
newAccount.Save();
string accEntryID = newAccount.EntryID;
Outlook.Folder businessContacts = (Outlook.Folder)bcmRootFolder.Folders["Business Contacts"];
Outlook.ContactItem newContact1 = (Outlook.ContactItem)businessContacts.Items.Add("IPM.Contact.BCM.Contact");
newContact1.FullName = "Hao Chen";
newContact1.FileAs = "Chen";
if (newContact1.UserProperties["Parent Entity EntryID"] == null)
{
userProp = newContact1.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = accEntryID;
}
newContact1.Account = newAccount.FileAs;
newContact1.Save();
string contactEntryID = newContact1.EntryID;
if (newAccount.UserProperties["PrimaryContactEntryID"] == null)
{
userProp = newAccount.UserProperties.Add("PrimaryContactEntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = contactEntryID;
}
newAccount.Save();
newContact1.UserProperties["Parent Entity EntryID"].Value = String.Empty;
newContact1.Account = String.Empty;
newContact1.Save();
}
VBA
Sub UnlinkContactsToAccount()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolders As Outlook.Folders
Dim bcmRootFolder As Outlook.Folder
Dim bcmAccountsFldr As Outlook.Folder
Dim bcmContactsFldr As Outlook.Folder
Dim newAcct As Outlook.ContactItem
Dim newContact1 As Outlook.ContactItem
Dim newContact2 As Outlook.ContactItem
Dim newContact3 As Outlook.ContactItem
Dim userProp As Outlook.UserProperty
Set olApp = CreateObject("Outlook.Application")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolders = objNS.Session.Folders
Set bcmRootFolder = olFolders("Business Contact Manager")
Set bcmAccountsFldr = bcmRootFolder.Folders("Accounts")
Set newAcct = bcmAccountsFldr.Items.Add("IPM.Contact.BCM.Account")
newAcct.FullName = "Wide World Importers"
newAcct.FileAs = "Wide World Importers"
newAcct.Save
Set bcmContactsFldr = bcmRootFolder.Folders("Business Contacts")
Set newContact1 = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
newContact1.FullName = "John Smith"
newContact1.FileAs = "John Smith"
If (newContact1.UserProperties("Parent Entity EntryID") Is Nothing) Then
Set userProp = newContact1.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newAcct.EntryID
End If
newContact1.Save
Set newContact2 = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
newContact2.FullName = "Rajesh Rotti"
newContact2.FileAs = "Rajesh Rotti"
If (newContact2.UserProperties("Parent Entity EntryID") Is Nothing) Then
Set userProp = newContact2.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newAcct.EntryID
End If
newContact2.Save
Set newContact3 = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
newContact3.FullName = "Isabel Martins"
newContact3.FileAs = "Isabel Martins"
If (newContact3.UserProperties("Parent Entity EntryID") Is Nothing) Then
Set userProp = newContact3.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newAcct.EntryID
End If
newContact3.Save
If (newAcct.UserProperties("PrimaryContactEntryID") Is Nothing) Then
Set userProp = newAcct.UserProperties.Add("PrimaryContactEntryID", olText, False, False)
userProp.Value = newContact3.EntryID
End If
newAcct.Save
newContact3.ItemProperties("Parent Entity EntryID").Value = ""
newContact3.Save
newContact2.ItemProperties("Parent Entity EntryID").Value = ""
newContact2.Save
newContact1.ItemProperties("Parent Entity EntryID").Value = ""
newContact1.Save
Set newAcct = Nothing
Set newContact3 = Nothing
Set newContact2 = Nothing
Set newContact1 = Nothing
Set bcmContactsFldr = Nothing
Set bcmAccountsFldr = Nothing
Set bcmRootFolder = Nothing
Set olFolders = Nothing
Set objNS = Nothing
Set olApp = Nothing
End Sub
See Also
Link Business Contacts to an Account | 2007 Office System: Updated Developer Content