Condividi tramite


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 Microsoft Visual Basic/Visual Basic for Applications (VBA) example accepts a TaskRequestItem, sending the response without displaying the inspector.

Sub AcceptTask()
    Dim myOlApp As New Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myTasks As Outlook.MAPIFolder
    Dim myNewTaskItem As Outlook.TaskItem
    Dim mytaskreqItem As Outlook.TaskRequestItem
    Dim myItem As Outlook.TaskItem
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set myTasks = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set mytaskreqItem = myTasks.Items.Find("[Subject] = ""Meeting w/ Nate Sun""")
    If Not TypeName(mytaskreqItem) = "Nothing" Then
        Set myNewTaskItem = mytaskreqItem.GetAssociatedTask(True)
        Set myItem = myNewTaskItem.Respond(olTaskAccept, True, True)
        myItem.Send
    End If
End Sub

If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript code.

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

Applies to | TaskRequestAcceptItem Object | TaskRequestDeclineItem Object | TaskRequestItem Object | TaskRequestUpdateItem Object