Programatically Assign Outlook Task

T

Todd Lemen

Referring to the VBA online help example for Assign
Method:

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)
myItem.Assign
Set myDelegate = myItem.Recipients.Add("April LaMonte")
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = #9/20/97#
myItem.Send

I understand that, in this example, "myOlApp" may
bedimensioned as follows:
Dim myOlApp As Object

I understand that, in this example, "myItem" may be
dimensioned as follows:
Dim myItem As Outlook.TaskItem

How is "myDelegate" dimensioned in this example?
 
S

Sue Mosher [MVP-Outlook]

Look at the method you're using: Recipients.Add returns a Recipient object.
 
T

Todd Lemen

OK... I'm missing something here...
The following code:
Sub Experiment()
Dim myOlApp As Object
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipients
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)
myItem.Assign
Set myDelegate = myItem.Recipients.Add("April LaMonte")
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = #9/20/1997#
myItem.Display
End Sub

return the following error at the "myItem.Assign" line:
***************
Runtime error '-2079309819{84104005}'
The task "" is stored as a file, not as an item in an
Outlook folder, so the requested action cannot be
performed.
**************
When I comment out the "Dim myDelegate" line, the code
doesn't break until the "Set myDelegate line...

Thanks,

TL
 
S

Sue Mosher [MVP-Outlook]

Weird error. But for one thing, you need to Dim myDelegate as Recipient, not
Recipients. From OL2003 Help:

Sub AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
Set MyItem = myOlApp.CreateItem(olTaskItem)
MyItem.Assign
Set myDelegate = MyItem.Recipients.Add("Dan Wilson")
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = Now + 30
myItem.Display
myItem.Send
End If
End Sub

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Todd Lemen

Set the Dim myDelegates line to "Recipient", same result
in Office XP, Office 2K3, and Office 2K, each a different
computer.
Entered code from OL2003 Help, same runtime error in
Office XP, Office 2K3, and Office 2K, each a different
computer.
Disabled anti-virus, same result...

Commented out the .Assign line, and Outlook displays a
task with the Assign button grayed out.

Suggestions or work-arounds? I wonder if I'm running into
some security code that did not exist when the help
instructions were written...
 
S

Sue Mosher [MVP-Outlook]

Runs fine here in OL 2003. Ar3e you running this code in Outlook VBA? Can
you assign a task manually?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Todd Lemen

Running from Access VBA, referencing the Outlook object
libraries, and granting permission for Access to... well,
access... Outlook for 10 minutes when the security window
pops.

Manual task assignments in Outlook work fine.

TL
 
S

Sue Mosher [MVP-Outlook]

Does it work from OL2003 VBA? If so, then we may have an interesting Access
issue. I'll try from Access here as well.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Todd Lemen

Works great from OL2K3, OLXP, OL2K.
TL
-----Original Message-----
Does it work from OL2003 VBA? If so, then we may have an interesting Access
issue. I'll try from Access here as well.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers






.
 
S

Sue Mosher [MVP-Outlook]

Works fine here in Access 2003. Maybe time to run Detect and Repair? Or try
Dim myDelegate as Object?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Todd Lemen

Thanks for all your help, Sue. I really appreciate it!
I decided to try an experiment. I added a line:
myItem.Save
prior to myItem.Assign. It works fine.
So, here's the procedure:
Sub Experiment()
Dim myOlApp As Object
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipients
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)
Set myDelegate = myItem.Recipients.Add("April LaMonte")
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = #9/20/1997#
myItem.Save
myItem.Assign
myItem.Display
End Sub

If saved before assign, Outlook recognizes the item as an
Outlook item, rather than a "file", and proceeds as
expected.

Thanks again!
TL
 
S

Sue Mosher [MVP-Outlook]

Glad you found a solution that works for you!
`
Todd Lemen said:
Thanks for all your help, Sue. I really appreciate it!
I decided to try an experiment. I added a line:
myItem.Save
prior to myItem.Assign. It works fine.
So, here's the procedure:
Sub Experiment()
Dim myOlApp As Object
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipients
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)
Set myDelegate = myItem.Recipients.Add("April LaMonte")
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = #9/20/1997#
myItem.Save
myItem.Assign
myItem.Display
End Sub

If saved before assign, Outlook recognizes the item as an
Outlook item, rather than a "file", and proceeds as
expected.

Thanks again!
TL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top