PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Outlook 2007 add-in: appointment changed event

 
 
Johan Machielse
Guest
Posts: n/a
 
      29th Jul 2008
Dear reader,

I've created an add-in for Outlook 2007; this add-in sets the color of the
appointments related to the location.

- In the OnStartupComplete() event all appointments will be colored.
- In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.

But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...

//_calendarItems is of type Outlook.MAPIFolder
_calendarItems.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);

//ItemChange event handler
void Items_ItemChange(object Item)
{
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
SetColorAppointment(appointment);
}

//changes color appointment (called within all events mentioned above)
private void SetColorAppointment(Outlook.AppointmentItem appointment)
{
int color = GetLocationColor(appointment.Location);


appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
{00062002-0000-0000-C000-000000000046}/82140003",
color);
appointment.Save();

}

When the SetColorAppointment() has been called; the event Item_ItemChange()
will be called again and again and again, because the item changed off
course! How can this behavour be solved?

I also tried this version of the SetColorAppointment() method (with
Redemption); the Items_ItemChange() will also be called again and again...

Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
safeAppointment.Item = appointment;
int propertyID =
safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
0x8214);
propertyID = propertyID | 0x3;
safeAppointment.set_Fields(propertyID, color);
//appointment.Subject = appointment.Subject;
appointment.Save();

I also tried using the Outlook.AppointmentItem.PropertyChange event. This
event fires when the Location property has been changed but when I handle
this event and try to set the colors of all appointments; the appointment
wherefrom I just changed the location still has the old location??? I checked
it and the case is that the I continuously change the color of the previous
location! During this event it seems like I don't have the current MAPIFolder
with the current appointment items?

void appointment_PropertyChange(string Name)
{
if ( Name == "Location" )
{
foreach (Outlook.AppointmentItem appointment in _items)
{
SetColorAppointment(appointment);
}
}
}

In Outlook 2003 I got it working with the Redemption method and
PropertyChange event, but this approach does not seem to work in Outlook
2007...

What is the best solution to catch the event that the location has been
changed of an appoinment and changing the color successfully in Outlook 2007?

Thank you in advance,

Johan Machielse

 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      29th Jul 2008
Setting a property of an item in ItemChange() will of course cause that
event to fire again. So you need to put a flag on the item as you change the
color to show it was already changed. An alternative would be to maintain a
list of items that have been changed in that event handler and if the item
is already in the list then don't change it again.

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


"Johan Machielse" <(E-Mail Removed)> wrote in
message news:48E169F2-C37D-49A3-B1E2-(E-Mail Removed)...
> Dear reader,
>
> I've created an add-in for Outlook 2007; this add-in sets the color of the
> appointments related to the location.
>
> - In the OnStartupComplete() event all appointments will be colored.
> - In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.
>
> But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...
>
> //_calendarItems is of type Outlook.MAPIFolder
> _calendarItems.ItemChange += new
> Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
>
> //ItemChange event handler
> void Items_ItemChange(object Item)
> {
> Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
> SetColorAppointment(appointment);
> }
>
> //changes color appointment (called within all events mentioned above)
> private void SetColorAppointment(Outlook.AppointmentItem appointment)
> {
> int color = GetLocationColor(appointment.Location);
>
>
> appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
> {00062002-0000-0000-C000-000000000046}/82140003",
> color);
> appointment.Save();
>
> }
>
> When the SetColorAppointment() has been called; the event
> Item_ItemChange()
> will be called again and again and again, because the item changed off
> course! How can this behavour be solved?
>
> I also tried this version of the SetColorAppointment() method (with
> Redemption); the Items_ItemChange() will also be called again and again...
>
> Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
> safeAppointment.Item = appointment;
> int propertyID =
> safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
> 0x8214);
> propertyID = propertyID | 0x3;
> safeAppointment.set_Fields(propertyID, color);
> //appointment.Subject = appointment.Subject;
> appointment.Save();
>
> I also tried using the Outlook.AppointmentItem.PropertyChange event. This
> event fires when the Location property has been changed but when I handle
> this event and try to set the colors of all appointments; the appointment
> wherefrom I just changed the location still has the old location??? I
> checked
> it and the case is that the I continuously change the color of the
> previous
> location! During this event it seems like I don't have the current
> MAPIFolder
> with the current appointment items?
>
> void appointment_PropertyChange(string Name)
> {
> if ( Name == "Location" )
> {
> foreach (Outlook.AppointmentItem appointment in _items)
> {
> SetColorAppointment(appointment);
> }
> }
> }
>
> In Outlook 2003 I got it working with the Redemption method and
> PropertyChange event, but this approach does not seem to work in Outlook
> 2007...
>
> What is the best solution to catch the event that the location has been
> changed of an appoinment and changing the color successfully in Outlook
> 2007?
>
> Thank you in advance,
>
> Johan Machielse
>


 
Reply With Quote
 
Johan Machielse
Guest
Posts: n/a
 
      29th Jul 2008
Yep, I ready figured it out! I used a flag to check if the appointment was
already changed!

Thank you Ken!

Johan

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

> Setting a property of an item in ItemChange() will of course cause that
> event to fire again. So you need to put a flag on the item as you change the
> color to show it was already changed. An alternative would be to maintain a
> list of items that have been changed in that event handler and if the item
> is already in the list then don't change it again.
>
> --
> 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
>
>
> "Johan Machielse" <(E-Mail Removed)> wrote in
> message news:48E169F2-C37D-49A3-B1E2-(E-Mail Removed)...
> > Dear reader,
> >
> > I've created an add-in for Outlook 2007; this add-in sets the color of the
> > appointments related to the location.
> >
> > - In the OnStartupComplete() event all appointments will be colored.
> > - In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.
> >
> > But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...
> >
> > //_calendarItems is of type Outlook.MAPIFolder
> > _calendarItems.ItemChange += new
> > Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
> >
> > //ItemChange event handler
> > void Items_ItemChange(object Item)
> > {
> > Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
> > SetColorAppointment(appointment);
> > }
> >
> > //changes color appointment (called within all events mentioned above)
> > private void SetColorAppointment(Outlook.AppointmentItem appointment)
> > {
> > int color = GetLocationColor(appointment.Location);
> >
> >
> > appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
> > {00062002-0000-0000-C000-000000000046}/82140003",
> > color);
> > appointment.Save();
> >
> > }
> >
> > When the SetColorAppointment() has been called; the event
> > Item_ItemChange()
> > will be called again and again and again, because the item changed off
> > course! How can this behavour be solved?
> >
> > I also tried this version of the SetColorAppointment() method (with
> > Redemption); the Items_ItemChange() will also be called again and again...
> >
> > Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
> > safeAppointment.Item = appointment;
> > int propertyID =
> > safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
> > 0x8214);
> > propertyID = propertyID | 0x3;
> > safeAppointment.set_Fields(propertyID, color);
> > //appointment.Subject = appointment.Subject;
> > appointment.Save();
> >
> > I also tried using the Outlook.AppointmentItem.PropertyChange event. This
> > event fires when the Location property has been changed but when I handle
> > this event and try to set the colors of all appointments; the appointment
> > wherefrom I just changed the location still has the old location??? I
> > checked
> > it and the case is that the I continuously change the color of the
> > previous
> > location! During this event it seems like I don't have the current
> > MAPIFolder
> > with the current appointment items?
> >
> > void appointment_PropertyChange(string Name)
> > {
> > if ( Name == "Location" )
> > {
> > foreach (Outlook.AppointmentItem appointment in _items)
> > {
> > SetColorAppointment(appointment);
> > }
> > }
> > }
> >
> > In Outlook 2003 I got it working with the Redemption method and
> > PropertyChange event, but this approach does not seem to work in Outlook
> > 2007...
> >
> > What is the best solution to catch the event that the location has been
> > changed of an appoinment and changing the color successfully in Outlook
> > 2007?
> >
> > Thank you in advance,
> >
> > Johan Machielse
> >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2002 - Recurring Meeting is changed into an appointment. Tommy Microsoft Outlook Calendar 0 27th Nov 2009 04:56 PM
Outlook 2007. Event ID 25, Event ID 2000. Microsoft Office 12. Event ID 2001 David F. Sage Microsoft Outlook Discussion 0 10th Mar 2008 02:24 PM
an event or appointment in the calendar in outlook 2007 does not w =?Utf-8?B?SXp6eQ==?= Microsoft Outlook Calendar 3 21st Jun 2007 02:47 AM
Daylight Savings Time changed my appointment times in Outlook =?Utf-8?B?Tmlr?= Microsoft Outlook Discussion 0 28th Mar 2007 01:15 AM
How to add an appointment (event) to outlook calendar from ASP page Tom Hwang Microsoft Outlook Program Addins 4 20th May 2004 09:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 PM.