Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / August 2004

Tip: Looking for answers? Try searching our database.

Accessing outlook events in Com-Addin

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shadow - 29 Jul 2004 13:48 GMT
I have written a Com-Addin (In VB) in which I need to access an
openitem event of an email form. I am new to it and don;t know what
needs to be done to make it work. This is my code, but I dont see the
code being executed when a new mailitem is created in outlook.  Please
help...

Option Explicit

Public oApplication As Outlook.Application
Public WithEvents INewInspectors As Outlook.Inspectors

'Public WithEvents INewInspectors As Inspectors
Public MyMail As MailItem

Implements IDTExtensibility2

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
' Occurs when the set of connected COM add-ins changes, that is when
' any other add-in is connected or disconnected.
' The custom argument is ignored.
End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
' If the COM add-in is connected, occurs when Outlook begins its
' shutdown routines.
' The custom argument is ignored.

End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As
Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode,
ByVal AddInInst As Object, custom() As Variant)
' Occurs when the COM add-in is connected.
' The Application argument is the Outlook Application object.
' The ConnectMode argument specifies how the COM add-in was connected.
' It can be
'     ext_cm_AfterStartup     Add-in was connected after Outlook
started,
'                             or the Connect property of the
corresponding
'                             COMAddIn object was set to True
'     ext_cm_Startup          Add-in was connected on startup
'     ext_cm_External
'     ext_cm_CommandLine
' The AddInInst argument is the COMAddIn object that refers to the
current
'     instance of the add-in itself.
' The custom argument is ignored.

Set oApplication = Application
Call Initialize_handler

'Set oNS = oApplication.GetNamespace("MAPI")
'Set MyMail = oApplication.CreateItem(olMailItem)
'MyMail.Subject = "TEST"

End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
' Occurs when the COM add-in is disconnected.
' The RemoveMode argument specifies how the COM add-in was
disconnected.
' It can be
'     ext_dm_HostShutdown      Add-in was disconnected when Outlook
was
'                              closed.
'     ext_dm_UserClosed        Add-in was disconnected when the user
'                              cleared the corresponding check box in
the
'                              COM Add-ins dialog box, or the Connect
'                              property of the corresponding COMAddIn
'                              object was set to False.
' The custom argument is ignored.
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
' If the COM add-in connects at startup, occurs when Outlook completes
' its startup routines. This event does not occur if the COM add-in is
not
' connected when Outlook loads, even when the user connects the add-in
in
' the COM Add-ins dialog box.
' The custom argument is ignored.
End Sub

Public Sub Initialize_handler()
   
   On Error Resume Next
   
   Set INewInspectors = oApplication.Inspectors
   
End Sub

' This function is called when we create a new inspector item,i.e. a
new mail

Public Sub INewInspectors_NewInspector(ByVal INewInspectors As
Outlook.Inspector)

   Set MyMail = INewInspectors.CurrentItem

   'check to see if message is created using a custom form
   If MyMail.MessageClass = "IPM.Note.BC_Message_WOCode" Then
   
       MyMail.Subject = "TEST"
       ' once I am here then I need to do more processing like
populating some custom fields etc.
       Exit Sub
   End If
End Sub
Sue Mosher [MVP-Outlook] - 07 Aug 2004 22:14 GMT
If you want to monitor MyMail's events, Open in particular, then you need to
declare it WithEvents, as you did INewInspectors.

Also, this procedure declaration has a major problem -- you're reusing the
INewInspectors variable:

Public Sub INewInspectors_NewInspector(ByVal INewInspectors As
Outlook.Inspector)

Instead, try:

Public Sub INewInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> I have written a Com-Addin (In VB) in which I need to access an
> openitem event of an email form. I am new to it and don;t know what
[quoted text clipped - 107 lines]
>     End If
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.