A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Item Write event is not always catched



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 24th 08, 11:51 AM posted to microsoft.public.outlook.program_addins
Carsten Gehling
external usenet poster
 
Posts: 1
Default Item Write event is not always catched

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  
Old January 24th 08, 03:43 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Item Write event is not always catched

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  
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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 10:30 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.