View Single Post
  #3  
Old May 6th 08, 03:57 PM posted to microsoft.public.outlook.program_addins
mikeo
external usenet poster
 
Posts: 7
Default How to create recurring appointment exceptions? VSTO 2k8

Hi Ken,

Thanks for your quick reply ...

You raise a good point - when I try to save the item (via
AppointmentItem.Save) I get the following exception (AccessViolationException
is caught by my "catch" statement) and the inspector window closes:

"Attempted to read or write protected memory. This is often an indication
that other memory is corrupt."

I find that the "non-exception" item that created, but the start date wasn't
updated. I assume that I'm not allowed in VSTO to explicitly save this item
that Outlook created via COM when I add a recurrence ... or could it be
related to releasing/not releasing COM objects appropriately?

Thanks a lot for your help,
Mike

"Ken Slovak - [MVP - Outlook]" wrote:

Changing the date of any existing instance of a recurring series will create
an exception, are you saving the item after applying the change to the start
date?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"mikeo" wrote in message
...
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




Ads