Appointments
You can schedule an Outlook appointment for an Account, Business Contact, Opportunity, or Business Project by creating an Appointment object and linking it with a new or existing Account, Business Contact, Opportunity, or Business Project object.
The following C# and Visual Basic for Applications (VBA) examples show how to create a new appointment and associate it with a new Account object.
C#
private void CreateAppointment()
{
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"];
//first create a BCM project
Outlook.Folder accounts = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];
Outlook.ContactItem newAcct = (Outlook.ContactItem)accounts.Items.Add("IPM.Contact.BCM.Account");
newAcct.FullName = "Wide World Importers";
newAcct.FileAs = "Wide World Importers";
newAcct.Email1Address = "someone@example.com";
newAcct.Save();
Outlook.Folder bcmHistoryFolder = (Outlook.Folder)bcmRootFolder.Folders["Communication History"];
//Create a Outlook Appointment
Outlook.AppointmentItem appointmentItem = (Outlook.AppointmentItem)bcmHistoryFolder.Items.Add("IPM.Appointment");
appointmentItem.Subject = "Meet to discuss the new architecture";
appointmentItem.Body = "Need to finalize on the Architecture...";
appointmentItem.Start = System.DateTime.Parse("3/20/2006 1:30:00 PM");
appointmentItem.Duration = 40;
appointmentItem.Save();
Outlook.JournalItem newHistoryTaskItem = (Outlook.JournalItem)bcmHistoryFolder.Items.Add("IPM.Activity.BCM");
newHistoryTaskItem.Subject = appointmentItem.Subject;
newHistoryTaskItem.Start = appointmentItem.Start;
newHistoryTaskItem.Duration = appointmentItem.Duration;
newHistoryTaskItem.Type = "Meeting";
//If the Outlook Appointment gets deleted, then the information is preserved in the Business Activity
newHistoryTaskItem.Body = "StartDate: " + appointmentItem.Start + "\n" + "Duration: " + appointmentItem.Duration;
if (newHistoryTaskItem.UserProperties["Parent Entity EntryID"] == null)
{
Outlook.UserProperty userProp = newHistoryTaskItem.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = newAcct.EntryID;
}
if (newHistoryTaskItem.UserProperties["LinkToOriginal"] == null)
{
Outlook.UserProperty userProp = newHistoryTaskItem.UserProperties.Add("LinkToOriginal", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = appointmentItem.EntryID;
}
newHistoryTaskItem.Save();
}
VBA
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
End Sub
See Also
About Communication History Items | 2007 Office System: Updated Developer Content