GetAssociatedTask Method

Microsoft Outlook Visual Basic

GetAssociatedTask Method

       

Returns a TaskItem object that represents the requested task.

Note The GetAssociatedTask method will not work unless the TaskItem is processed before the method is called. To do so, call the Display method before calling GetAssociatedTask.

expression.GetAssociatedTask(AddToTaskList)

expression   Required. An expression that returns one of the objects in the Applies To list.

AddToTaskList   Required Boolean. True if the task is added to the default Tasks folder.

Example

This example accepts a TaskRequestItem, sending the response without displaying the inspector.

Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myTasks = myNameSpace.GetDefaultFolder(olFolderInbox)
Set mytaskreqItem = myTasks.items.Find _
    ("[Subject] = ""Meeting w/ Jerry Wheeler""")
If Not TypeName(mytaskreqItem) = "Nothing" Then
   'The task is displayed.
   mytaskreqItem.Display
   Set myNewTaskItem = mytaskreqItem.GetAssociatedTask(True)
   myNewTaskItem.Respond olTaskAccept, True, True
End If

If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNamespace("MAPI")
Set myTasks = myNameSpace.GetDefaultFolder(6)
Set myTaskReqItem = myTasks.items.Find("[Subject] = ""Meeting w/ Jerry Wheeler""")
If Not TypeName(myTaskReqItem) = "Nothing" Then
   'The task is displayed.
   myTaskReqItem.Display
   Set myNewTaskItem = myTaskReqItem.GetAssociatedTask(True)
   myNewTaskItem.Respond 2, True, True
End If