M
mikeo
I am writing an Outlook 2007 Add-in using VSTO 2008 (VB .NET). I want to
allow the user to add an appointment that is associated with an existing
recurring appointment. The catch is that the given date may not fit the
recurrence pattern. For example, if the user has an Inspector window open
with an occurence of an "every Thursday" appointment, he may choose to add a
Monday. I know the object model supports it because I can do it manually by
selecting a recurrance and changing the start date.
I have been able to programmatically add a new "non-exception" meeting by
calling AppointmentItem.GetRecurrencePattern and incrementing
recurPattern.Occurrences. I can also refer to the new appointment via
recurPattern.GetOccurence(date). However, I haven't found a way to update
the appointment start date and create an exception. Here is some of the code
I've been trying:
' Add an appointment for this date
Public Sub AddDate(ByVal dt As Date)
Dim inspector As Outlook._Inspector = Nothing
Dim apptItem As Outlook.AppointmentItem = Nothing
Dim recurPattern As Outlook.RecurrencePattern = Nothing
Dim newDate As Date
Dim newApptItem As Outlook.AppointmentItem = Nothing
Dim origEndDate As Date
Try
inspector = OutlookApp.ActiveInspector
Catch
End Try
If inspector IsNot Nothing Then
apptItem = inspector.CurrentItem
If apptItem.IsRecurring Then
Try
' get the recurrence pattern
recurPattern = apptItem.GetRecurrencePattern
' get a new meeting by incrementing the occurrences
recurPattern.Occurrences += 1
' get the newly-created appointment item
newDate = New Date(recurPattern.PatternEndDate.Year, _
recurPattern.PatternEndDate.Month, _
recurPattern.PatternEndDate.Day, _
recurPattern.StartTime.Hour, _
recurPattern.StartTime.Minute, _
recurPattern.StartTime.Second)
newApptItem = recurPattern.GetOccurrence(newDate)
' set the start date of the new meeting to the desired
date
newDate = New Date(dt.Year, dt.Month, dt.Day, _
recurPattern.StartTime.Hour, _
recurPattern.StartTime.Minute, _
recurPattern.StartTime.Second)
' this update gets lost if newDate is out of the
recurrence pattern ....
newApptItem.Start = newDate
Catch
End Try
Else
' need to make it recurring ...
End If
End If
If inspector IsNot Nothing Then Marshal.ReleaseComObject(inspector)
If apptItem IsNot Nothing Then Marshal.ReleaseComObject(apptItem)
If recurPattern IsNot Nothing Then
Marshal.ReleaseComObject(recurPattern)
If newApptItem IsNot Nothing Then
Marshal.ReleaseComObject(newApptItem)
End Sub
Is there a better approach to add an "exception" appointment to an existing
recurrence pattern? Or, to put it another way, is there a way in VSTO to set
the appointment conversationIndex to associate it with other appointments?
Any suggestions are greatly appreciated.
Thanks,
mikeo
allow the user to add an appointment that is associated with an existing
recurring appointment. The catch is that the given date may not fit the
recurrence pattern. For example, if the user has an Inspector window open
with an occurence of an "every Thursday" appointment, he may choose to add a
Monday. I know the object model supports it because I can do it manually by
selecting a recurrance and changing the start date.
I have been able to programmatically add a new "non-exception" meeting by
calling AppointmentItem.GetRecurrencePattern and incrementing
recurPattern.Occurrences. I can also refer to the new appointment via
recurPattern.GetOccurence(date). However, I haven't found a way to update
the appointment start date and create an exception. Here is some of the code
I've been trying:
' Add an appointment for this date
Public Sub AddDate(ByVal dt As Date)
Dim inspector As Outlook._Inspector = Nothing
Dim apptItem As Outlook.AppointmentItem = Nothing
Dim recurPattern As Outlook.RecurrencePattern = Nothing
Dim newDate As Date
Dim newApptItem As Outlook.AppointmentItem = Nothing
Dim origEndDate As Date
Try
inspector = OutlookApp.ActiveInspector
Catch
End Try
If inspector IsNot Nothing Then
apptItem = inspector.CurrentItem
If apptItem.IsRecurring Then
Try
' get the recurrence pattern
recurPattern = apptItem.GetRecurrencePattern
' get a new meeting by incrementing the occurrences
recurPattern.Occurrences += 1
' get the newly-created appointment item
newDate = New Date(recurPattern.PatternEndDate.Year, _
recurPattern.PatternEndDate.Month, _
recurPattern.PatternEndDate.Day, _
recurPattern.StartTime.Hour, _
recurPattern.StartTime.Minute, _
recurPattern.StartTime.Second)
newApptItem = recurPattern.GetOccurrence(newDate)
' set the start date of the new meeting to the desired
date
newDate = New Date(dt.Year, dt.Month, dt.Day, _
recurPattern.StartTime.Hour, _
recurPattern.StartTime.Minute, _
recurPattern.StartTime.Second)
' this update gets lost if newDate is out of the
recurrence pattern ....
newApptItem.Start = newDate
Catch
End Try
Else
' need to make it recurring ...
End If
End If
If inspector IsNot Nothing Then Marshal.ReleaseComObject(inspector)
If apptItem IsNot Nothing Then Marshal.ReleaseComObject(apptItem)
If recurPattern IsNot Nothing Then
Marshal.ReleaseComObject(recurPattern)
If newApptItem IsNot Nothing Then
Marshal.ReleaseComObject(newApptItem)
End Sub
Is there a better approach to add an "exception" appointment to an existing
recurrence pattern? Or, to put it another way, is there a way in VSTO to set
the appointment conversationIndex to associate it with other appointments?
Any suggestions are greatly appreciated.
Thanks,
mikeo