![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I have made an Addin for Outlook 2003 using VSTO. I want it to handle
changes to Appointment Items in the users calendar. But I have a problem regarding handling the item-events. If you look at the code below, I try to handle the Item's Write event, put up a message and "cancel" the event to make sure, that the item is NOT saved. My problem lies in that the event-handler is not called on all save events. The very first time I open an appointment item, changes e.g. the Subject and press "Save" - my event-handler is called. But on all subsequent saves, it is not called (even if I change some of the properties) This is my code - quite simple: ------------------------------------------------------------------------------ Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup Try ' Handle when an inspector window is opened with e.g. an appointment item selectInspectors = Me.Inspectors() AddHandler selectInspectors.NewInspector, AddressOf Me.NewInspector_Event Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub NewInspector_Event(ByVal new_Inspector As Outlook.Inspector) Dim appItem As Outlook.AppointmentItem appItem = new_Inspector.CurrentItem ' Handle if items are deleted AddHandler appItem.Write, AddressOf Me.Item_Write_Event End Sub Private Sub Item_Write_Event(ByRef Cancel As Boolean) MsgBox("Don't do it") Cancel = True End Sub ------------------------------------------------------------------------------ Kind regards Carsten Gehling |
#2
|
|||
|
|||
![]()
Your event handler along with the reference it relies on are being garbage
collected and therefore no longer are valid. Declare appItem at the class level so it stays alive and doesn't get garbage collected. I'd advise the same thing for your Inspectors collection so your NewInspector event handler stays alive. -- 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 "Carsten Gehling" wrote in message ... I have made an Addin for Outlook 2003 using VSTO. I want it to handle changes to Appointment Items in the users calendar. But I have a problem regarding handling the item-events. If you look at the code below, I try to handle the Item's Write event, put up a message and "cancel" the event to make sure, that the item is NOT saved. My problem lies in that the event-handler is not called on all save events. The very first time I open an appointment item, changes e.g. the Subject and press "Save" - my event-handler is called. But on all subsequent saves, it is not called (even if I change some of the properties) This is my code - quite simple: ------------------------------------------------------------------------------ Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup Try ' Handle when an inspector window is opened with e.g. an appointment item selectInspectors = Me.Inspectors() AddHandler selectInspectors.NewInspector, AddressOf Me.NewInspector_Event Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub NewInspector_Event(ByVal new_Inspector As Outlook.Inspector) Dim appItem As Outlook.AppointmentItem appItem = new_Inspector.CurrentItem ' Handle if items are deleted AddHandler appItem.Write, AddressOf Me.Item_Write_Event End Sub Private Sub Item_Write_Event(ByRef Cancel As Boolean) MsgBox("Don't do it") Cancel = True End Sub ------------------------------------------------------------------------------ Kind regards Carsten Gehling |
#3
|
|||
|
|||
![]()
appItem needs to be declared at the class level. Otherwise, it will go out of scope and cease firing events. Release it in its Close event.
Or better yet, use a wrapper class, so you can handle multiple open appointments. See http://www.outlookcode.com/codedetail.aspx?id=1344 for an example. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Carsten Gehling" wrote in message ... I have made an Addin for Outlook 2003 using VSTO. I want it to handle changes to Appointment Items in the users calendar. But I have a problem regarding handling the item-events. If you look at the code below, I try to handle the Item's Write event, put up a message and "cancel" the event to make sure, that the item is NOT saved. My problem lies in that the event-handler is not called on all save events. The very first time I open an appointment item, changes e.g. the Subject and press "Save" - my event-handler is called. But on all subsequent saves, it is not called (even if I change some of the properties) This is my code - quite simple: ------------------------------------------------------------------------------ Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup Try ' Handle when an inspector window is opened with e.g. an appointment item selectInspectors = Me.Inspectors() AddHandler selectInspectors.NewInspector, AddressOf Me.NewInspector_Event Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub NewInspector_Event(ByVal new_Inspector As Outlook.Inspector) Dim appItem As Outlook.AppointmentItem appItem = new_Inspector.CurrentItem ' Handle if items are deleted AddHandler appItem.Write, AddressOf Me.Item_Write_Event End Sub Private Sub Item_Write_Event(ByRef Cancel As Boolean) MsgBox("Don't do it") Cancel = True End Sub ------------------------------------------------------------------------------ Kind regards Carsten Gehling |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
appointment 'Write' event not firing as expected | JohnV@nn | Add-ins for Outlook | 1 | May 24th 07 12:18 AM |
ContactItem Write event not getting called | Dave | Add-ins for Outlook | 1 | April 19th 07 07:44 AM |
Write event not firing in list view | Rick H | Add-ins for Outlook | 2 | February 21st 07 03:53 PM |
Write RTF-Body on ItemSend event | Thomas | Add-ins for Outlook | 2 | February 12th 07 12:22 PM |
How to write new calendar event from internet application? | jhajko via OfficeKB.com | Outlook - Calandaring | 2 | May 9th 06 04:56 PM |