Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete past tasks (2003)

    I'm trying to write some code that will delete any tasks that should be finished, and update the project start date to today's date. Here's what I have so far:

    Sub DeleteOld()
    Dim t As Task, a As Collection
    Set a = New Collection
    For Each t In ActiveProject.Tasks
    If t.Finish < Now() Then
    a.Add t.UniqueID
    End If
    Next t
    Do Until a.Count = 0
    i = 1
    <span style="background-color: #FFFF00; color: #000000; font-weight: bold">Do Until ActiveProject.Tasks(i).UniqueID = a(1)</span hi>
    i = i + 1
    Loop
    ActiveProject.Tasks(i).Delete
    Loop
    ActiveProject.StartOnCurrentDate = True
    End Sub

    My problem is that when executing the highlighted loop, Project goes right the way through the existing tasks without finding a task with UniqueID = a(1). I thought the point of UniqueID was that it doesn't change - yet evidently something is wrong.

    Any ideas? Is there a better way to achieve my objectives?
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  2. #2
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solved...

    I've managed to sort it out - there were some elementary errors, and some lack of understanding of project to blame. My basic problem was that, unknown to me, deleting a parent task deleted all its subtasks. Here's the code that works:

    Sub DeleteOld()
    Dim t As Task, a As Collection
    Set a = New Collection
    For Each t In ActiveProject.Tasks
    If t.Finish < Now() Then
    a.Add t.UniqueID
    End If
    Next t
    For Each b In a
    i = 1
    Do Until i > ActiveProject.Tasks.Count
    If ActiveProject.Tasks(i).UniqueID = b Then Exit Do Else i = i + 1
    Loop
    If i <= ActiveProject.Tasks.Count Then ActiveProject.Tasks(i).Delete
    Next b
    ActiveProject.ProjectStart = Date
    End Sub
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Solved...

    Hi,

    Glad to see you figured out your code. However, deleting completed tasks is a dangerous undertaking based on how predecessors and successors are setup and whether or not you are using a baseline. By doing so, you lose any reference to how your earlier work completed that you could reference in other projects and you lose the ability to run analyses to see if perhaps, you could improve your performance if the work was done differently. You also lose any data on effort that is complete to see how much resources have been used.

    A better way to reduce the number of tasks that you see is by running a filter where you can exclude completed tasks so you dont lose any history. I have seen several times where managers marked tasks at 100% complete that were NOT complete and had to be corrected, that is, you had to undo the 100% in a future month. This wreaks havoc with your schedule but if the tasks were deleted, there would not be no way to do this. Anyway, Just my <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>
    Regards,

    Gary
    (It's been a while!)

  4. #4
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Solved...

    Thanks, Gary, that's probably good advice for people who use Project properly! I'm actually only using it (in this instance) as an ongoing work scheduler, so I don't use it for tracking progress at all - merely for putting tasks in the right order. I then have another macro which shoves those tasks into my Outlook calendar. This macro doesn't delete any past tasks - so I can still see the older tasks in Outlook, and only use Project to reschedule my future work.

    For a true project, with a definite beginning and end, you're absolutely right that it would make no sense to delete completed tasks - but for a rolling work schedule, it (hopefully) makes sense.
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •