Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

Handle the TaskItem's Open event

Hi

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
0
ToHo
Asked:
ToHo
  • 2
1 Solution
 
meschCommented:
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)
    myOlMItem.Save
    Set myOlAtts = myOlMItem.Attachments
    ' Add new contact to attachments in mail message
    myOlAtts.Add Item, olByValue
    myOlMItem.To = "Sales Team"
    myOlMItem.Subject = "New contact"
    myOlMItem.Send
End Sub

</norbert>
0
 
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)
0
 
ToHoAuthor Commented:
Hi

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

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now