Handle the TaskItem's Open event


I've been trying to figure out how to recieve an event i VBA when the user tries to open a task. I've created an object, but I guess I have to initialize this somehow. Hope someone can help..

Here's what I've got:

Dim WithEvents myTaskItem As Outlook.TaskItem

Private Sub myTaskItem_Open(Cancel As Boolean)
    MsgBox "Opening task"
End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hey ToHo,

I think this is a good sample. It's form the Outlook VBA help file. I think you forgot the initialize handler.

Dim myOlApp As Outlook.Application
Public WithEvents myOlItems As Outlook.Items

Public Sub Initialize_handler()
    Set myOlItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
    Dim myOlMItem As Outlook.MailItem
    Dim myOlAtts As Outlook.Attachments
    Set myOlMItem = myOlApp.CreateItem(olMailItem)
    Set myOlAtts = myOlMItem.Attachments
    ' Add new contact to attachments in mail message
    myOlAtts.Add Item, olByValue
    myOlMItem.To = "Sales Team"
    myOlMItem.Subject = "New contact"
End Sub

ToHoAuthor Commented:
Hi norberg, and thanks for your response.

I've figured out how to handle events generally, but it's the event triggered when a task is opened I have a hard time with.

What I'm trying to achieve is to check when a task is opened if has one of my custom properties, and open a custom form if it does. Else I just want the regular task form to be launced.

I've gotten this to work if I declare a task with withevents and use this to create a new task, but this will only work with this one task. I want to catch an event on all opened task.. Maybe I'll have to write a com-plugin to achieve this, but I'm hoping there's is an easier way (ex. VBA)
ToHoAuthor Commented:

I figured it out; I had to make a collection of classes to receive the events.
PAQ'd and all 125 points refunded.

Community Support Moderator @Experts Exchange

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.