Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook addin ItemAdd event not being triggered

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

I wrote an Outlook macro to make sure an email was filed in the correct sent items folder. To distribute it to all staff it seems the best way to do this is to convert it to an Outlook add-in which I am attempting to do in Visual Studio 2010.

The problem is that the ItemAdd event is not being triggered.

Code:
Option Explicit On

Public Class ThisAddIn
    Private Fold1, Fold2 As Outlook.MAPIFolder
    Private WithEvents colItems1 As Outlook.Items

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        Fold1 = Application.GetNamespace("MAPI").GetDefaultFolder(5)
        colItems1 = Fold1.Items
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        'Clean Up
        Fold1 = Nothing
        Fold2 = Nothing
        colItems1 = Nothing
    End Sub

    Private Sub colItems1_ItemAdd(ByVal Item As Object)

        On Error GoTo errHandler

        MsgBox("New email detected!")

        'This sub runs when a new item is detected in the user's sent items
        'e.g. when they send an email
        Fold2 = Application.GetNamespace("MAPI").Folders(Item.SenderName).Folders("Sent Items")
        If Fold1.Parent.Name <> Fold2.Parent.Name Then
            Item.Move(Fold2)
        Else
        End If

errHandler:
        If Err.Number <> 0 Then
            MsgBox("Could not move email to sent items of " & Item.SenderName)
        End If
        Err.Clear()
    End Sub

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top