Sub CreateAppointment()
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 bcmHistoryFolder As Outlook.Folder
Dim newAcct As Outlook.ContactItem
Dim newHistoryTaskItem As Outlook.JournalItem
Dim newAppItem As Outlook.AppointmentItem
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 bcmHistoryFolder = bcmRootFolder.Folders("Communication History")
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 newAppItem = olApp.CreateItem(olAppointmentItem)
newAppItem.Subject = "Meet to discuss the new architecture"
newAppItem.Body = "Need to finalize on the Architecture..."
newAppItem.Start = #3/20/2006 1:30:00 PM#
newAppItem.Duration = 40
newAppItem.Save
Set newHistoryTaskItem = bcmHistoryFolder.Items.Add("IPM.Activity.BCM")
newHistoryTaskItem.Subject = newAppItem.Subject
newHistoryTaskItem.Start = newAppItem.Start
newHistoryTaskItem.Duration = newAppItem.Duration
newHistoryTaskItem.Type = "Meeting"
'If the Outlook Appointment gets deleted, then the information is preserved in the body of the Business Activity
newHistoryTaskItem.Body = "StartDate: " & newAppItem.Start & vbNewLine & "Duration: " & newAppItem.Duration
If (newHistoryTaskItem.UserProperties("Parent Entity EntryID") Is Nothing) Then
Set userProp = newHistoryTaskItem.UserProperties.Add("Parent Entity EntryID", olText, False, False)
userProp.Value = newAcct.EntryID
End If
If (newHistoryTaskItem.UserProperties("LinkToOriginal") Is Nothing) Then
Set userProp = newHistoryTaskItem.UserProperties.Add("LinkToOriginal", olText, False, False)
userProp.Value = newAppItem.EntryID
End If
newHistoryTaskItem.Save
Set newAppItem = Nothing
Set newHistoryTaskItem = Nothing
Set newAcct = Nothing
Set bcmAccountsFldr = Nothing
Set bcmHistoryFolder = Nothing
Set bcmRootFolder = Nothing
Set olFolders = Nothing
Set objNS = Nothing
Set olApp = Nothing