Create an Opportunity linked to a Business Contact

You can create an Opportunity object and link it to a new or existing Business Contact object. If linked with a Business Contact, the History section of the Business Contact form displays details of the Opportunity and the Link To field on the Opportunity form displays the Business Contact name.

The following C# and Visual Basic for Applications (VBA) examples show how to create a new Opportunity and link it to a new Business Contact object.

C#

  private void CreateOpportunityWithBusinessContact()
        {

            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 contacts = (Outlook.Folder)bcmRootFolder.Folders["Business Contacts"];
            
            Outlook.ContactItem newContact =
            (Outlook.ContactItem)contacts.Items.Add("IPM.Contact.BCM.Contact");

            newContact.FullName = "John Smith";
            newContact.FileAs = "John";
            newContact.Save();

            string contactEntryID = newContact.EntryID;

            Outlook.Folder opportunities = (Outlook.Folder)bcmRootFolder.Folders["Opportunities"];
            Outlook.TaskItem newOpportunity =
            (Outlook.TaskItem)opportunities.Items.Add("IPM.Task.BCM.Opportunity");
            newOpportunity.Subject = "Sales Opp with John Smith";

            if (newOpportunity.UserProperties["Account Name"] == null)
            {
                Outlook.UserProperty userProp = newOpportunity.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = contactEntryID;
            }

            newOpportunity.Save();

        }



VBA

  Sub CreateOpportunityWithBusinessContact()

   Dim olApp As Outlook.Application
   Dim objNS As Outlook.NameSpace
   Dim olFolders As Outlook.Folders
   Dim bcmRootFolder As Outlook.Folder
   Dim bcmContactsFldr As Outlook.Folder
   Dim bcmOppFolder As Outlook.Folder
   Dim newContact As Outlook.ContactItem
   Dim newOpportunity As Outlook.TaskItem

   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 bcmOppFolder = bcmRootFolder.Folders("Opportunities")

   Set newContact = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
   newContact.FullName = "John Smith"
   newContact.FileAs = "John Smith"
   newContact.Email1Address = "someone@example.com"
   newContact.Save

   Set newOpportunity = bcmOppFolder.Items.Add("IPM.Task.BCM.Opportunity")
   newOpportunity.Subject = "Opportunity For Wide World Importers to enter into Retail Field"
   
   If (newOpportunity.UserProperties("Parent Entity EntryID") Is Nothing) Then
        Set userProp = newOpportunity.UserProperties.Add("Parent Entity EntryID", olText, False, False)
        userProp.Value = newContact.EntryID
   End If

   newOpportunity.Save

   Set newOpportunity = Nothing
   Set newContact = Nothing
   Set bcmOppFolder = Nothing
   Set bcmContactsFldr = Nothing
   Set bcmRootFolder = Nothing
   Set olFolders = Nothing
   Set objNS = Nothing
   Set olApp = Nothing

End Sub

See Also

Select an Opportunity | Edit an Opportunity | Delete an Opportunity | Create an Opportunity linked to an Account | 2007 Office System: Updated Developer Content