Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / May 2008

Tip: Looking for answers? Try searching our database.

How to create recurring appointment exceptions?  VSTO 2k8

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mikeo - 06 May 2008 00:12 GMT
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
Ken Slovak - [MVP - Outlook] - 06 May 2008 14:24 GMT
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?

Signature

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

>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
[quoted text clipped - 83 lines]
> Thanks,
> mikeo
mikeo - 06 May 2008 15:57 GMT
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

> 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
[quoted text clipped - 87 lines]
> > Thanks,
> > mikeo
Ken Slovak - [MVP - Outlook] - 07 May 2008 00:01 GMT
I don't see VSTO preventing any saves of items. It's mostly a shim loader
and wrapper for unhandled exceptions and for the IDTExtensibility
interfaces.

I think the problem is your algorithm. If you extend the number of
occurrences the new item goes at the end of the series. You are trying to
reschedule the new appointment to some other date, triggering the Outlook
error: "cannot reschedule an occurrence if it skips over a later occurrence
of the same appointment". That's the problem.

What you'd have to do is to change the occurrence just after the new desired
date to that date, change the following appointment to the date of the
occurrence you just changed, repeat for every occurence in the series to
avoid that error. It would be hell to manage and code, if it would even work
at all.

And if it did work you'd end up with the entire series being exceptions.

As I said, this has nothing to do with VSTO or Outlook version. It's a
limitation of the implementation of RecurrencePattern and its binary blob.

Signature

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

> Hi Ken,
>
[quoted text clipped - 17 lines]
> Thanks a lot for your help,
> Mike
mikeo - 09 May 2008 22:35 GMT
Hi Ken,

Thanks again for your insightful feedback.

I'm not convinced that this is the specific issue.  Since the addition of
exception items is fundamental to the requirements for my add-in, I'm not
ready to throw in the towel yet ...  

I receive the protected memory exception even if the item I'm trying to
create/save remains as the last item in the pattern.  For example, the last
recurrence of a weekly recurring meeting is on Friday, May 9th.  When my code
increments recurPattern.Occurrences by 1, Outlook creates a new occurence on
Friday, May 16th.  When I programmatically try to update the Start date of
this new item to Thu May 15, I get the error.  Note that Outlook lets me do
this manually (i.e. increment Occurrences by 1, save, open the new last
recurrence, update date, save.

Any other theories as to what is going wrong here?  Debugging suggestions?

Thanks,
mikeo

> I don't see VSTO preventing any saves of items. It's mostly a shim loader
> and wrapper for unhandled exceptions and for the IDTExtensibility
[quoted text clipped - 38 lines]
> > Thanks a lot for your help,
> > Mike
Ken Slovak - [MVP - Outlook] - 12 May 2008 14:04 GMT
No other suggestions, my guess is that Outlook doesn't like your
incrementing Occurrences in code. But that's just a guess.

Signature

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

> Hi Ken,
>
[quoted text clipped - 21 lines]
> Thanks,
> mikeo

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.