Class Modules and WithEvents

Roland Askew

Member
Outlook version
Outlook 2021 64 bit
Email Account
IMAP
Any help with this would be really appreciated.
I have set up a class module and have it monitoring the default task folder. The module intialize but the event does not ever fire.
The code is as follows: I am using Outlook 2021.

Public Sub Application_Startup()
Set FolderT = New clsFolderTask
End Sub

In the class module I have
Private WithEvents Items As Outlook.Items

Sub Class_Initialize()
Dim Ns As Outlook.Namespace
Dim TaskFolder As Outlook.MAPIFolder
Dim Destfolder As Outlook.MAPIFolder
Dim Items As Items
Dim objApp As Application
Dim objViews As Views
Dim objView As View

Set objApp = Outlook.Application
Set Ns = Application.GetNamespace("MAPI")
Set TaskFolder = Ns.GetDefaultFolder(olFolderTasks)
Set Destfolder = TaskFolder.Folders("Completed") ' Subfolder of the Task Folder
Set Items = TaskFolder.Items
'Applies view to select folder
Set objViews = TaskFolder.Views
Set objView = objViews.Item("Tasks")
objView.Apply
End Sub

Private Sub Items_ItemChange(ByVal Item As Object)
Dim Ns As Outlook.Namespace
Dim TaskFolder As Outlook.MAPIFolder
Dim Destfolder As Outlook.MAPIFolder

Set Ns = Application.GetNamespace("MAPI")
Set TaskFolder = Ns.GetDefaultFolder(olFolderTasks)
Set Destfolder = TaskFolder.Folders("Completed")

If TypeOf objItem Is Outlook.TaskItem Then
If objItem.Status = olTaskComplete Then
Item.Move Destfolder
MsgBox "Completed and moved to Completed Folder"
End If
End If
End Sub


Any thoughts as to what might need to be changed
Thanks
Roland
 
Hi Diane
Thanks for your response. Tried what you suggested and also looked at the Microsoft Items.ItemAdd event (Outlook) webpage and managed to rewrite the code to work with these suggestions.
Thanks again.
Roland
 
Similar threads
Thread starter Title Forum Replies Date
S Unable to change Message Class Outlook VBA and Custom Forms 0
S Changing Message Class Outlook VBA and Custom Forms 4
Witzker HowTo Change message Class of contact form Outlook VBA and Custom Forms 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
W Message class changes of a custom form changes to the default form Using Outlook 2
P Message Class keeps changing back to IPM.Contact Outlook VBA and Custom Forms 2
J Outlook 2007 - Change Message Class for all Items in Folder Outlook VBA and Custom Forms 1
K pr_container class missing Using Outlook 1
L Moving Message Class email via script and Rule Outlook VBA and Custom Forms 3
1 Outlook Message Class Exchange Server Administration 3
M RDO: using TypeOf to determine [OOM] Class Outlook VBA and Custom Forms 1
H How to make hourglass and change back to default in Outlook class ? Outlook VBA and Custom Forms 3
K cannot instantiate abstract class - Compiler error. Outlook VBA and Custom Forms 3
S Failed to create an RDO session instance: Class not registered Outlook VBA and Custom Forms 1
S Changed Message class; forms with data resist. Outlook VBA and Custom Forms 5
T Changing Icon of message class Outlook VBA and Custom Forms 1
F WithEvents not working Using Outlook 2
M Create email from Access on Outlook and make sure that email has beensent using WithEvents method Outlook VBA and Custom Forms 3

Similar threads

Back
Top