Delete Shared Task

  • Thread starter Thread starter Job
  • Start date Start date
J

Job

Trying to delete a shared task. Using this example:

Sub DeleteSharedTask()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim strFind As String
Dim objCalFolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim objAppt As Outlook.TaskItem
Dim myRecipient As Outlook.recipient

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set myRecipient = objNS.CreateRecipient("USER XYZ")
myRecipient.Resolve
If myRecipient.Resolved Then
Set objTaskFolder = objNS.GetSharedDefaultFolder(myRecipient,
olFolderTasks)
Set colTask = objTaskFolder.Items
strFind = "[Subject] = " & Chr(34) & "Test Delete" & Chr(34)
Set objTask = colTask.Find(strFind)
If Not objTask Is Nothing Then
objTask.Delete
End If
End If
Set objOL = Nothing
Set objNS = Nothing
Set objCalFolder = Nothing
Set colCalendar = Nothing
End Sub

Error on the objTask.Delete = The operation failed. An object could not be
found.

I can debug and display the item, change the item, look at all of the
itemproperties, but not delete. I have been granted ownership rights to the
user's shared tasks. Any suggestions?
 
This really shouldn't make any difference, but see if it does. Grab the
EntryID and StoreID of the task item and release your objTask reference,
then reinstantiate that or a new task object and see if you can then delete
it.
 
Ken,

Your giving me too much credit. I'm not sure how to do what you've
suggested. Would it be like this?

a = objTask.Item("EntryID").Value
b = objTask.Item("StoreID").Value

Set objTask = Nothing
Set objTask = ...
not sure where to go..pretty new to this...thanks for your help

Ken Slovak - said:
This really shouldn't make any difference, but see if it does. Grab the
EntryID and StoreID of the task item and release your objTask reference,
then reinstantiate that or a new task object and see if you can then
delete it.




Job said:
Trying to delete a shared task. Using this example:

Sub DeleteSharedTask()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim strFind As String
Dim objCalFolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim objAppt As Outlook.TaskItem
Dim myRecipient As Outlook.recipient

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set myRecipient = objNS.CreateRecipient("USER XYZ")
myRecipient.Resolve
If myRecipient.Resolved Then
Set objTaskFolder = objNS.GetSharedDefaultFolder(myRecipient,
olFolderTasks)
Set colTask = objTaskFolder.Items
strFind = "[Subject] = " & Chr(34) & "Test Delete" & Chr(34)
Set objTask = colTask.Find(strFind)
If Not objTask Is Nothing Then
objTask.Delete
End If
End If
Set objOL = Nothing
Set objNS = Nothing
Set objCalFolder = Nothing
Set colCalendar = Nothing
End Sub

Error on the objTask.Delete = The operation failed. An object could not
be found.

I can debug and display the item, change the item, look at all of the
itemproperties, but not delete. I have been granted ownership rights to
the user's shared tasks. Any suggestions?
 
Tried this and it gave me the same error:

If Not objTask Is Nothing Then
a = objTask.ItemProperties.Item("EntryID").Value
b = objTaskFolder.StoreID
End If

Set objTask = Nothing
For Each t In colTask
If t.ItemProperties.Item("EntryID").Value = a And
objTaskFolder.StoreID = b Then
t.Delete
End If
Next t



Ken Slovak - said:
This really shouldn't make any difference, but see if it does. Grab the
EntryID and StoreID of the task item and release your objTask reference,
then reinstantiate that or a new task object and see if you can then
delete it.




Job said:
Trying to delete a shared task. Using this example:

Sub DeleteSharedTask()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim strFind As String
Dim objCalFolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim objAppt As Outlook.TaskItem
Dim myRecipient As Outlook.recipient

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set myRecipient = objNS.CreateRecipient("USER XYZ")
myRecipient.Resolve
If myRecipient.Resolved Then
Set objTaskFolder = objNS.GetSharedDefaultFolder(myRecipient,
olFolderTasks)
Set colTask = objTaskFolder.Items
strFind = "[Subject] = " & Chr(34) & "Test Delete" & Chr(34)
Set objTask = colTask.Find(strFind)
If Not objTask Is Nothing Then
objTask.Delete
End If
End If
Set objOL = Nothing
Set objNS = Nothing
Set objCalFolder = Nothing
Set colCalendar = Nothing
End Sub

Error on the objTask.Delete = The operation failed. An object could not
be found.

I can debug and display the item, change the item, look at all of the
itemproperties, but not delete. I have been granted ownership rights to
the user's shared tasks. Any suggestions?
 
Try this:

a = objTask.EntryID
b = objTask.Parent.StoreID

Set objTask = Nothing

Set objTask = oNS.GetItemFromID(a, b)
If Not (objTask Is Nothing) Then
objTask.Delete
Set objTask = Nothing
End If

What version of Outlook? Where is this code running? It's obviously either
VB6 or VBA code.
 
Thanks for the code. It gives the same message. This has to do something
with the shared nature of the task. I can delete a shared task via code if
i have the item selected in the window. For example I have a user PMO who
shares it's tasks and I'm on owner. If I select that task folder then I can
delete. It's when I'm referring to a shared task folder that is not in the
current window.

I'm using Outlook 2007. The code is running in that environment, VBA.
 
The purpose of the code is to do the following:

We want to use the tasks capability of Outlook and Exchange for project
managment. The only way we've found to be able to assign tasks and have a
central location is to assign a dummy user 'PMO' which shares it's tasks and
give every user ownership rights. So each task that is assigned to users is
essentially from PMO. The difficulty comes from the inability to recall the
task. If I've assigned the task to UserA and I decided that I wanted to
change the hours, not only on the main PMO, but also on the users machine,
I've either got to have each of the user's shared folders avail to select
and change (which would be too confusing for a lot of our users) or we came
up with the idea to have a button or something that essentially (when in the
PMO view) copies the selected task and fills in the custom fields to the new
copied version of the task. As the task is copied it reassigns the task to
PMO as the owner. Now we need to get rid of the task on the UserA's personal
task list, thus the code you are helping with. The copied task would then
be re-assigned to the user with the relevant changes.

If we were able to effectivly recall the task it would make the process
easier. However, I have all of the code to do everything described above
minus the deleting of the original task off of the users personal task list
to whom the task was orignially assigned.
 
Do you open the shared mailbox as part of the Outlook profile? I've found in
a lot of my code that things don't work as expected in delegate mailboxes
unless the mailbox is opened as part of the profile and not by using File,
Open in the UI or GetSharedDefaultFolder in code.
 
Ken,

Are you talking about File>Open>Other User's Folder>Tasks? For this
particular user, yes I have that open, though in my code I get at that
folder by way of GetSharedDefaultFolder.
 
Yes, those are what I meant. That might be the root of the problem possibly.
 
Hmmm...that kind of defeats the purpose of the 'behind the scenes' code. I
didn't want to have everyone have to open everyone's task folder. It seems
there must be a way to delete a task from a shared folder in which you have
ownership rights using GetSharedDefaultFolder. Would you approach the
problem completely differently? Is there a way to open the users shared
folders without actually displaying them? Is there a way to say
objItem.display (but make it not visible) and then pass some key strokes to
delete and not to decline (you know that little window that pops up)?

Thanks for your feedback on this Ken.
 
I never use SendKeys for something like that, it's a real hack.

If you call item.Display() the item will be shown, that's what the call is
for.

I really haven't had a problem with using GetSharedDefaultFolder myself, I'm
just trying to help you figure out why your code isn't working. Usually if
you get the error you've gotten it's a permissions issue, the item isn't
available or it's open in another application, or you've modified it or held
a reference to the object somewhere else. Another possibility is a custom
form with code that modified that item.
 
Ok,
The task that is being referred to is always going to be a custom form. Do I
have to refer to the task that is on a custom form differently. Sorry didn't
occur to me that that would change the way you interact with it..
 
No, you don't refer to it differently but if the form has code behind it
that modifies that item in any way that would be the source of your problem.
You can try and see if saving the item in the form code after any
modifications helps but I suspect that you might just have to rewrite the
form code to not modify anything and handle any changes you want in the
addin code instead to be able to do what you want.
 
I've found that if the user creates a regular task then I can delete it
perfectly fine with the code. However, it has the problem when the task has
been assigned to that user from another user say PMO, then I cannot delete
it, but I can look at all of the values etc, if I have the write to email I
can re-assign the task (though we don't want everyone to have delegated
email rights). Any ideas?
 
Ken,

What would also work is if we created another folder in everone's outlook
tasks called..'Trash'. Then we could find the correct task and move it on
the shared users computer to that new folder. Is this possible? If so, how
do you refer to a different folder within 'My Tasks' folders?
 
I don't follow your last 2 posts at all.

Are you referring to the NavigationPane My Tasks? In Outlook 2003 you have
no access at all to that using code, in Outlook 2007 you can use the
Explorer.NavigationPane.NavigationGroups.NavigationGroup(olTaskModule)
object.
 
Let's see, if you have UserA and UserB. UserB shares his tasks with UserA
and gives UserA ownership rights. UserA can delete UserB's tasks. However,
if UserA creates a new task and assigns it to UserB, the task now changes
it's properties somehow into a quasi email item and UserA cannot delete that
task from UserB. However, if UserB gives UserA editor rights to UserB's
Inbox, then UserA CAN delete the task which was assigned. Since my last
post I've spent two days on the phone with Outlook developers from MS and
they have indicated that it is an application limitation.

So, if I can't delete it, maybe I can Move it to another folder in UserB's
tasks. So same scenario as above.

UserB gives permissions to UserA. UserB has a Tasks folder but has also
created a "Trash" folder in the tasks. My question earlier was how do I
access this "Trash" tasks folder on the UserB's machine?

Set Fldr2 = olNs2.GetSharedDefaultFolder _
(UserB, "Trash" folder in the tasks)

Can you look at the NavigationPane in the 'My Tasks' of UserB if you are
UserA?
 
It makes sense though that you can't delete it under those circumstances,
you assigned ownership of the item to someone else.

You can look at someone else's Navigation Pane only if you log into their
mailbox as them. Otherwise in Outlook 2003 the Navigation Pane stuff is
stored in an XML file based on the Outlook profile name plus some random
stuff stored in a hidden message in the hidden Common Views folder.

You can't use GetSharedDefaultFolder to get the Tasks folder and navigate
from there to Trash, you'll just get an error. That method doesn't give you
a folder with the full set of normal properties or store permissions. You'd
basically have to logout of that Outlook session and start a new session
logging into the other user's mailbox.

The alternative is if you open the mailbox as part of your profile. If it's
opened that way you can use NameSpace.Folders to iterate the open stores
until you get the other mailbox, then walk it's folder hierarchy to find the
Trash folder. But that won't work unless the mailbox is opened as part of
the profile.

In Outlook 2007 you could use NameSpace.Stores to get to the top of each
loaded store if you wanted that. That;s new for Outlook 2007 though.
 
Back
Top