View Single Post
  #3  
Old January 24th 08, 01:32 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Item Write event is not always catched

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

Ads