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