• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Attach Sent Item to Task

I've got a custom form which sends a message to an addressee and on the Send event automatically creates a task based on the content of the message.  Is it possible to attach the entire sent message to the task at the same time the task is created?

Here's the vbscript I'm using to create the task:

Sub Item_Send()
Set objOutlook = CreateObject("Outlook.application")
Set itmTask = objOutlook.CreateItem(olTaskItem)
With itmTask
.Subject = item.Subject
.Categories = "Contract Request"
.DueDate = NextBusinessDay(now(),7)
.ReminderTime = NextBusinessDay(now(), 5)
.ReminderSet = True
.Body = "Automatically created task based on " & item.Subject & vbCr & vbCr & item.body
End With
itmTask.Save
Set itmTask = Nothing
Set objOutlook = Nothing
End Sub  
0
snipsey
Asked:
snipsey
1 Solution
 
David LeeCommented:
Hi snipsey,

I've never gotten into creating/modifying Outlook forms so I can't speak directly to whether this is doable from a form or not.  It is doable from Outlook though if you trap the Application_ItemSend event.  In the sample code below I'm allowing a task to be created for every item sent, which of course isn't what you want.  You'd need to put in a test to only catch your modified form being sent.  But this code demonstrates that it is possible, at least at the application level.  

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim itmTask As Outlook.TaskItem
    Set itmTask = Application.CreateItem(olTaskItem)
    With itmTask
        .Subject = Item.Subject
        .Categories = "Contract Request"
        .DueDate = NextBusinessDay(now(),7)
        .ReminderTime = NextBusinessDay(now(),5)
        .ReminderSet = True
        .Body = "Automatically created task based on " & Item.Subject & vbCr & vbCr & Item.Body
        Item.Save
        .Attachments.Add Item
        .Save
    End With
    Set itmTask = Nothing
End Sub


Cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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