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 bcmProjectsFolder As Outlook.Folder
Dim bcmProjectTasksFolder As Outlook.Folder
Dim existAcct As Outlook.ContactItem
Dim newProject As Outlook.TaskItem
Dim newProjectTask As Outlook.TaskItem
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.Email1Address = "someone@example.com"
newAcct.Save
Set bcmProjFolder = bcmRootFolder.Folders("Business Projects")
Set newProject = bcmProjFolder.Items.Add("IPM.Task.BCM.Project")
newProject.Subject = "Sales Project with Wide World Importers"
If (newProject.UserProperties("Source of Lead") Is Nothing) Then
Set userProp = newProject.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newAcct.EntryID
End If
newProject.Save
Set bcmProjectTasksFolder = bcmProjFolder.Folders("Project Tasks")
Set newProjectTask = bcmProjectTasksFolder.Items.Add("IPM.Task.BCM.ProjectTask")
newProjectTask.Subject = "Task 1 for Sales Project with Wide World Importers"
If (newProjectTask.UserProperties("Source of Lead") Is Nothing) Then
Set userProp = newProjectTask.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newProject.EntryID
End If
newProjectTask.Save
Set newProject = Nothing
Set newProjectTask = Nothing
Set existAcct = Nothing
Set bcmAccountsFldr = Nothing
Set bcmProjectsFolder = Nothing
Set bcmProjectTasksFolder = Nothing
Set olFolders = Nothing
Set bcmRootFolder = Nothing
Set objNS = Nothing
Set olApp = Nothing