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 » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Events Question



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 4th 08, 03:26 PM posted to microsoft.public.outlook.program_vba
kalukaley
external usenet poster
 
Posts: 8
Default Events Question

Below is a copy of the code that I'm using to catch when someone updates an
item in their calendar.

How would I alter this code to capture an event any appointment in the
calendar.
Also, if one of the appointments is a recurring appointment how do I capture
the update of a single item in the series rather than an update to the entire
series?

Public WithEvents myItem As AppointmentItem

Private Sub Application_Startup()
Set myItem =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).Items.GetFirst

End Sub

Private Sub myItem_PropertyChange(ByVal Name As String)
MsgBox "The " & Name & " property changed."
End Sub
Ads
  #2  
Old February 4th 08, 03:37 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Events Question

That event you're handling won't catch a lot of changes. It also will fail
to work after a while since the myItem object will be out of scope once
Application_Startup() finishes and the garbage collector will remove that
reference and its events. Always declare an object variable at a class level
to keep it alive and therefore keep the events alive.

You can handle the events for the Items collection of the Calendar folder.
Declare that Items collection at class level and then handle the ItemAdd,
ItemChange and ItemRemove events.

For recurring events you have to get the master appointment, after testing
IsRecurring on the item. If it is recurring then use GetRecurrencePattern to
get at RecurrencePattern.Parent to get the master appointment. Never access
the RecurrencePattern unless IsRecurring is true, it will make the
non-recurring item recurring.

Once you have the master appointment you can see if there are any changes to
individual occurrences by checking the RecurrencePattern.Exceptions
collection, which has all modified and deleted occurrences.

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


"kalukaley" wrote in message
...
Below is a copy of the code that I'm using to catch when someone updates
an
item in their calendar.

How would I alter this code to capture an event any appointment in the
calendar.
Also, if one of the appointments is a recurring appointment how do I
capture
the update of a single item in the series rather than an update to the
entire
series?

Public WithEvents myItem As AppointmentItem

Private Sub Application_Startup()
Set myItem =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).Items.GetFirst

End Sub

Private Sub myItem_PropertyChange(ByVal Name As String)
MsgBox "The " & Name & " property changed."
End Sub


  #3  
Old February 4th 08, 09:56 PM posted to microsoft.public.outlook.program_vba
kalukaley
external usenet poster
 
Posts: 8
Default Events Question

I'm still waiting for my Outlook Programming book to arrive so, I'm relying
on online samples.

HANDLE ITEMS COLLECTION AT CLASS LEVEL
-----------------------------------------------------
I took this to mean that I should use the class Module

i've looked at many of the MSDN examples and they say to declare my
"Initialize_handler" function in a class module along with the handlers.

They say to call Initialize_handler method before events can be handled. I
tried calling it from "Application_Startup()" in "ThisOutlookSession" but I
just get the message Sub or Fucntion not defined.

-------------------------------------------------------------------------------
Code from class Module
Note: I really only threw in a msgbox to make sure the method
was being called. I'm not going to bother writing extra code, if I can't
make sure
the method is being called.
-------------------------------------------------------------------------------
Public WithEvents CalItems As Outlook.items

Public Sub Initialize_handler()

Set CalItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).items

MsgBox "I'm here"
End Sub

-------------------------------------------------------------
Code from "ThisOutlookSession"
-------------------------------------------------------------

Private Sub Application_Startup()
Initialize_handler

End Sub


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

That event you're handling won't catch a lot of changes. It also will fail
to work after a while since the myItem object will be out of scope once
Application_Startup() finishes and the garbage collector will remove that
reference and its events. Always declare an object variable at a class level
to keep it alive and therefore keep the events alive.

You can handle the events for the Items collection of the Calendar folder.
Declare that Items collection at class level and then handle the ItemAdd,
ItemChange and ItemRemove events.

For recurring events you have to get the master appointment, after testing
IsRecurring on the item. If it is recurring then use GetRecurrencePattern to
get at RecurrencePattern.Parent to get the master appointment. Never access
the RecurrencePattern unless IsRecurring is true, it will make the
non-recurring item recurring.

Once you have the master appointment you can see if there are any changes to
individual occurrences by checking the RecurrencePattern.Exceptions
collection, which has all modified and deleted occurrences.

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


"kalukaley" wrote in message
...
Below is a copy of the code that I'm using to catch when someone updates
an
item in their calendar.

How would I alter this code to capture an event any appointment in the
calendar.
Also, if one of the appointments is a recurring appointment how do I
capture
the update of a single item in the series rather than an update to the
entire
series?

Public WithEvents myItem As AppointmentItem

Private Sub Application_Startup()
Set myItem =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).Items.GetFirst

End Sub

Private Sub myItem_PropertyChange(ByVal Name As String)
MsgBox "The " & Name & " property changed."
End Sub



  #4  
Old February 4th 08, 10:13 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Events Question

If the event handler and init code is in a class module you'd have to
instantiate an instance of that class in the Application_Startup() code, and
the class would have to retain scope after Application_Startup() ended.

A class has no existence until an instance of it is instantiated.

Let's say the class module was named myClass. Then to use it you'd do this
in ThisOutlookSession:

Dim classHandler As New myClass

Then in Application_Startup() the call would look like this:

classHandler.Initialize_handler

A simpler approach would be to move all of your class code into the
ThisOutlookSession class module. The WithEvents declarations would be at the
top of the module, above any procedures. Initialize_handler() would be in
ThisOutlookSession also and could be Private if you want, it wouldn't have
to be Public.

In that case the call to the Initialize_handler would look like it does now.

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


"kalukaley" wrote in message
...
I'm still waiting for my Outlook Programming book to arrive so, I'm
relying
on online samples.

HANDLE ITEMS COLLECTION AT CLASS LEVEL
-----------------------------------------------------
I took this to mean that I should use the class Module

i've looked at many of the MSDN examples and they say to declare my
"Initialize_handler" function in a class module along with the handlers.

They say to call Initialize_handler method before events can be handled.
I
tried calling it from "Application_Startup()" in "ThisOutlookSession" but
I
just get the message Sub or Fucntion not defined.

-------------------------------------------------------------------------------
Code from class Module
Note: I really only threw in a msgbox to make sure the method
was being called. I'm not going to bother writing extra code, if I can't
make sure
the method is being called.
-------------------------------------------------------------------------------
Public WithEvents CalItems As Outlook.items

Public Sub Initialize_handler()

Set CalItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).items

MsgBox "I'm here"
End Sub

-------------------------------------------------------------
Code from "ThisOutlookSession"
-------------------------------------------------------------

Private Sub Application_Startup()
Initialize_handler

End Sub


  #5  
Old February 4th 08, 10:49 PM posted to microsoft.public.outlook.program_vba
kalukaley
external usenet poster
 
Posts: 8
Default Events Question

Almost There. I noticed that I didn't include the actual hanlder. The
Inialize_handler is now being called (message box is working).

However, the ItemChange Event doesn't appear to be called.

I have a recurring Appointment in my calendar. as a simple test I change
the duration or start time ( or any other thing ) in the appointment then
save it.
At this point I'm expecting a pop-up from my eventhandler ... but nothing
happens.

P.S. The future of this code is more than just dopey pop-ups


--------------------------------------------------------------------
From CLASS MODULE
-------------------------------------------------------------------
Public WithEvents CalItems As Outlook.items

Public Sub Initialize_handler()

Set CalItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).items

MsgBox "I'm here"
End Sub


Public Sub CalItems_ItemChange(ByVal Item As Object)
MsgBox "now I am here"

End Sub

-----------------------------------------------------------------------
From ThisOutLookSession
-----------------------------------------------------------------------
Dim classHandler As New Class1


Private Sub Application_Startup()

classHandler.Initialize_handler



End Sub
"kalukaley" wrote:

Below is a copy of the code that I'm using to catch when someone updates an
item in their calendar.

How would I alter this code to capture an event any appointment in the
calendar.
Also, if one of the appointments is a recurring appointment how do I capture
the update of a single item in the series rather than an update to the entire
series?

Public WithEvents myItem As AppointmentItem

Private Sub Application_Startup()
Set myItem =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).Items.GetFirst

End Sub

Private Sub myItem_PropertyChange(ByVal Name As String)
MsgBox "The " & Name & " property changed."
End Sub

  #6  
Old February 5th 08, 02:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Events Question

Does the event fire if you modify a non-recurring appointment?

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


"kalukaley" wrote in message
...
Almost There. I noticed that I didn't include the actual hanlder. The
Inialize_handler is now being called (message box is working).

However, the ItemChange Event doesn't appear to be called.

I have a recurring Appointment in my calendar. as a simple test I change
the duration or start time ( or any other thing ) in the appointment then
save it.
At this point I'm expecting a pop-up from my eventhandler ... but nothing
happens.

P.S. The future of this code is more than just dopey pop-ups


--------------------------------------------------------------------
From CLASS MODULE
-------------------------------------------------------------------
Public WithEvents CalItems As Outlook.items

Public Sub Initialize_handler()

Set CalItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).items

MsgBox "I'm here"
End Sub


Public Sub CalItems_ItemChange(ByVal Item As Object)
MsgBox "now I am here"

End Sub

-----------------------------------------------------------------------
From ThisOutLookSession
-----------------------------------------------------------------------
Dim classHandler As New Class1


Private Sub Application_Startup()

classHandler.Initialize_handler



End Sub


  #7  
Old February 5th 08, 03:28 PM posted to microsoft.public.outlook.program_vba
kalukaley
external usenet poster
 
Posts: 8
Default Events Question

Thanks Ken, turns out that I left out a simple step. I needed to close out
of outlook and get back in; all the tidbits you gave me were right on target.

Do you have a website. I'd like to go through your information.

There's a lot of information out there, but a lot of it assumes a certain
level of knowledge that tyro's like me simply don't have.

Thanks again.

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

Does the event fire if you modify a non-recurring appointment?

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


"kalukaley" wrote in message
...
Almost There. I noticed that I didn't include the actual hanlder. The
Inialize_handler is now being called (message box is working).

However, the ItemChange Event doesn't appear to be called.

I have a recurring Appointment in my calendar. as a simple test I change
the duration or start time ( or any other thing ) in the appointment then
save it.
At this point I'm expecting a pop-up from my eventhandler ... but nothing
happens.

P.S. The future of this code is more than just dopey pop-ups


--------------------------------------------------------------------
From CLASS MODULE
-------------------------------------------------------------------
Public WithEvents CalItems As Outlook.items

Public Sub Initialize_handler()

Set CalItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderCalendar).items

MsgBox "I'm here"
End Sub


Public Sub CalItems_ItemChange(ByVal Item As Object)
MsgBox "now I am here"

End Sub

-----------------------------------------------------------------------
From ThisOutLookSession
-----------------------------------------------------------------------
Dim classHandler As New Class1


Private Sub Application_Startup()

classHandler.Initialize_handler



End Sub



  #8  
Old February 5th 08, 04:05 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Events Question

My Web site is referenced in my signature.

The best reference for Outlook coding is at www.outlookcode.com. That site
has tons of sample code and articles about developing for Outlook.

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


"kalukaley" wrote in message
...
Thanks Ken, turns out that I left out a simple step. I needed to close
out
of outlook and get back in; all the tidbits you gave me were right on
target.

Do you have a website. I'd like to go through your information.

There's a lot of information out there, but a lot of it assumes a certain
level of knowledge that tyro's like me simply don't have.

Thanks again.


 




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
"Recurring events" glitch when categorzing events in Outlook Cal 2 dwarfdog Outlook - Calandaring 1 November 29th 07 09:55 PM
single events change to recurring events without a prompt. TPDavidson Outlook - Calandaring 0 February 12th 07 04:48 AM
Getting rid of duplicate events vs. Recurring events AK Outlook - Calandaring 1 September 29th 06 01:23 PM
1-Day Events randomly turn into 2-Day Events MJWUSTL Outlook - Calandaring 1 August 16th 06 05:25 PM
Item open events and double click events in exchange client extension. Fanxa Add-ins for Outlook 1 August 9th 06 08:18 AM


All times are GMT +1. The time now is 11:14 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.