Create an Account

The following C# and Visual Basic for Applications (VBA) examples show how to create a new Account object and assign to it some basic information about the account, such as the Account name, primary contact, business address, telephone, and e-mail address.

C#

  private void CreateAccount()
        {
            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 accounts = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];
            Outlook.UserProperty userProp;

            Outlook.ContactItem newAccount = (Outlook.ContactItem)accounts.Items.Add("IPM.Contact.BCM.Account");

            newAccount.FullName = "Wide World Importers";
            newAccount.FileAs = "Wide World Importers";

            newAccount.BusinessAddressStreet = "4567 Main Street, Suite# J 225";
            newAccount.BusinessAddressCity = "Redmond";
            newAccount.BusinessAddressState = "Washington";
            newAccount.BusinessAddressPostalCode = "07457";
            newAccount.BusinessAddressCountry = "United States";

            newAccount.BusinessTelephoneNumber = "+1-425-555-0100";
            newAccount.Email1Address = "someone@example.com";
            newAccount.WebPage = "www.wideworldimporters.com";

            if (newAccount.UserProperties["Account Name"] == null)
            {
                userProp = newAccount.UserProperties.Add("Account Name", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "Wide World Importers";
            }

            if (newAccount.UserProperties["Source of Lead"] == null)
            {
                userProp = newAccount.UserProperties.Add("Source of Lead", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "Advertisement";
            }

            if (newAccount.UserProperties["Territory"] == null)
            {
                userProp = newAccount.UserProperties.Add("Territory", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "North";
            }

            newAccount.Save();

        }


VBA

  Sub CreateAccount()

   Dim olApp As Outlook.Application
   Dim objNS As Outlook.NameSpace
   Dim bcmRootFolder As Outlook.Folder
   Dim olFolders As Outlook.Folders
   Dim bcmAccountsFldr As Outlook.Folder
   Dim newAcct 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"
   newAcct.FileAs = "Wide World"
   newAcct.Email1Address = "someone@example.com"

   If (newAcct.UserProperties("Source of Lead") Is Nothing) Then
        Set userProp = newAcct.UserProperties.Add("Source of Lead", olText, False, False)
        userProp.Value = "Advertisement"
   End If
   
   If (newAcct.UserProperties("Territory") Is Nothing) Then
        Set userProp = newAcct.UserProperties.Add("Territory", olText, False, False)
        userProp.Value = "North"
   End If
   
   newAcct.Save

   Set newItemProp = Nothing
   Set newAcct = Nothing
   Set bcmAccountsFldr = Nothing
   Set bcmRootFolder = Nothing
   Set olFolders = Nothing
   Set objNS = Nothing
   Set olApp = Nothing

End Sub 

See Also

Select an Account | Edit an Account | Delete an Account | Link Business Contacts to an Account | Create a Business Project linked to a Primary Account | Create an Opportunity linked to an Account | 2007 Office System: Updated Developer Content