Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Task Error 1

Status
Not open for further replies.

mrbboy

Technical User
Feb 28, 2007
136
US
I am using the folllowing code to try to send an Outlook task but I a getting an error everytime. The error is:

Run-time error '-1871691771 (90404005)'

THe task is stored as a file, not as an item in an Outlook folder, so the requested action can not be performed.

Code:

Dim OutlookApp As New Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim AssignedTo As Outlook.Recipient

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)

OutlookTask.Assign
Set AssignedTo = OutlookTask.Recipients.Add("mrbboy@comcast.net")
OutlookTask.Subject = "You have been assigned a task. See CAR Number "
OutlookTask.Body = "Test"
OutlookTask.DueDate = Now
OutlookTask.Importance = (olImportanceHigh)
OutlookTask.ReminderSet = True
OutlookTask.Save
OutlookTask.Send

OutlookApp.Quit
Set oulookTask = Nothing

When I run the code, I get the error message and OutlookTask.Assign is highlighted. Can someone tell me why I can't assign the task to the recipient?
 
Remou,

The code is similar to the one in the thread that you provided. I tried that code and I get the same run0time error message at the same spot.
 
Apparently, you need to log on first:

Code:
Dim OutlookApp As New outlook.Application
Dim OutlookTask As outlook.TaskItem
Dim AssignedTo As outlook.Recipient
'****
Dim olNS As outlook.NameSpace
'****

Set OutlookApp = CreateObject("Outlook.Application")
    
'****
Set olNS = OutlookApp.GetNamespace("MAPI")
olNS.Logon
'****

Set OutlookTask = OutlookApp.CreateItem(olTaskItem)

OutlookTask.Assign
Set AssignedTo = OutlookTask.Recipients.Add("mrbboy@comcast.net")
OutlookTask.Subject = "You have been assigned a task. See CAR Number "
OutlookTask.Body = "Test"
OutlookTask.DueDate = Now
OutlookTask.Importance = (olImportanceHigh)
OutlookTask.ReminderSet = True
OutlookTask.Save
OutlookTask.Send
'OutlookTask.Display

OutlookApp.Quit
Set OutlookTask = Nothing
 
Thanks Remou.

That worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top