Problems with Task.Work in MSP 2003

  • Thread starter Leif Ingar Iversen
  • Start date
L

Leif Ingar Iversen

Hi!

In MSP 2003, we're experiencing a problem with the Task.Work-value
after resource assignments are added to a task programmatically.
Earlier versions works just fine, but even the latest servicepack (SP2)
for MSP 2003 does not. We have recreated the problem with the following
vba-code that can be executed from for example excel:

Private Sub CommandButton1_Click()
Dim strResourceName, strActivityDescription As String
Dim ProjObj As MSProject.Application
Dim myResource As Resource
Dim myTask As Task
Dim myAssignment As Assignment
Dim ncounter As Integer

Set ProjObj = GetObject(, "MSProject.Application")
ProjObj.Calculation = False

'Adding resources to project
Set myResource = ProjObj.ActiveProject.Resources.Add("Peter")
Set myResource = ProjObj.ActiveProject.Resources.Add("Paul")
Set myResource = ProjObj.ActiveProject.Resources.Add("Mary")

'Adding activities and assignments

For ncounter = 1 To 3

Set myTask = ProjObj.ActiveProject.Tasks.Add
myTask.Name = "Activity " + CStr(ncounter)
myTask.Type = pjFixedDuration
myTask.EffortDriven = False
myTask.Duration = 10 * ncounter * 60
mytaskwork = 0

For Each myResource In ProjObj.ActiveProject.Resources
Set myAssignment =
myTask.Assignments.Add(ResourceID:=myResource.ID)
myAssignment.Work = 5 * ncounter * 60
mytaskwork = mytaskwork + myAssignment.Work
Next
MsgBox ("Activity " + CStr(ncounter) + " - Task.Work: " +
CStr(myTask.Work / 60) + " Sum of assignments: " + CStr(mytaskwork /
60))
Next ncounter
End Sub

For the 3 activities, the msgbox will in MSP2003 show:
"Activity 1 - Task.Work: 20 Sum of assignments: 15"
"Activity 2 - Task.Work: 40 Sum of assignments: 30"
"Activity 3 - Task.Work: 60 Sum of assignments: 45"

....while in MSP2002 it will show:
"Activity 1 - Task.Work: 15 Sum of assignments: 15"
"Activity 2 - Task.Work: 30 Sum of assignments: 30"
"Activity 3 - Task.Work: 45 Sum of assignments: 45"

The problem is that the Task.Work-value is incorrectly calculated in
MSP 2003 - this can best be seen in the Task Usage-view right after
executing this macro. As soon as you do something manually with the
assignments it will be correctly calculated.

I'm wondering if this is a known issue, and if so does there exist a
fix or a workaround to get the Work-value to be calculated correctly in
MSP 2003?

Thanks!

Best Regards
Leif Ingar Iversen
IFS Research & Development
http://www.ifsworld.com
 
J

Jack Dahlgren

Leif Ingar Iversen said:
Hi!

In MSP 2003, we're experiencing a problem with the Task.Work-value
after resource assignments are added to a task programmatically.
Earlier versions works just fine, but even the latest servicepack (SP2)
for MSP 2003 does not. We have recreated the problem with the following
vba-code that can be executed from for example excel:

Private Sub CommandButton1_Click()
Dim strResourceName, strActivityDescription As String
Dim ProjObj As MSProject.Application
Dim myResource As Resource
Dim myTask As Task
Dim myAssignment As Assignment
Dim ncounter As Integer

Set ProjObj = GetObject(, "MSProject.Application")
ProjObj.Calculation = False

'Adding resources to project
Set myResource = ProjObj.ActiveProject.Resources.Add("Peter")
Set myResource = ProjObj.ActiveProject.Resources.Add("Paul")
Set myResource = ProjObj.ActiveProject.Resources.Add("Mary")

'Adding activities and assignments

For ncounter = 1 To 3

Set myTask = ProjObj.ActiveProject.Tasks.Add
myTask.Name = "Activity " + CStr(ncounter)
myTask.Type = pjFixedDuration
myTask.EffortDriven = False
myTask.Duration = 10 * ncounter * 60
mytaskwork = 0

For Each myResource In ProjObj.ActiveProject.Resources
Set myAssignment =
myTask.Assignments.Add(ResourceID:=myResource.ID)
myAssignment.Work = 5 * ncounter * 60
mytaskwork = mytaskwork + myAssignment.Work
Next
MsgBox ("Activity " + CStr(ncounter) + " - Task.Work: " +
CStr(myTask.Work / 60) + " Sum of assignments: " + CStr(mytaskwork /
60))
Next ncounter
End Sub

For the 3 activities, the msgbox will in MSP2003 show:
"Activity 1 - Task.Work: 20 Sum of assignments: 15"
"Activity 2 - Task.Work: 40 Sum of assignments: 30"
"Activity 3 - Task.Work: 60 Sum of assignments: 45"

...while in MSP2002 it will show:
"Activity 1 - Task.Work: 15 Sum of assignments: 15"
"Activity 2 - Task.Work: 30 Sum of assignments: 30"
"Activity 3 - Task.Work: 45 Sum of assignments: 45"

The problem is that the Task.Work-value is incorrectly calculated in
MSP 2003 - this can best be seen in the Task Usage-view right after
executing this macro. As soon as you do something manually with the
assignments it will be correctly calculated.

I'm wondering if this is a known issue, and if so does there exist a
fix or a workaround to get the Work-value to be calculated correctly in
MSP 2003?

Thanks!

Sorry I don't have proj2003 available to check this on. But your comment
that once you do something manually then the calculations are correct makes
me think that you should try a
CalculateAll
after inserting the data.

-Jack Dahlgren
http://zo-d.com/blog
 
L

Leif Ingar Iversen

Jack said:
Sorry I don't have proj2003 available to check this on. But your comment
that once you do something manually then the calculations are correct makes
me think that you should try a
CalculateAll
after inserting the data.

-Jack Dahlgren
http://zo-d.com/blog

Thanks for your suggestion. Unfortunately, doing a project calculation
at the end of the export from our application is not an option since it
will reschedule the whole project and make it impossible to compare
with the source.

Anyway, I tried your suggestion by adding...

ProjObj.CalculateAll

....at the end of my script. The result is the same, the summarized work
values for the task in the Task Usage-views are still wrong. Even doing
a manual project calculation using
Tools->Options/Calculation->Calculate Now makes no difference.

Any other ideas or suggestions are highly appreciated! :)

Best Regards
Leif Ingar Iversen
IFS Research & Development
http://www.ifsworld.com
 
R

Rod Gill

Hi,

There does look to be a bug here. I re-did the macro to run in Project and
the bug still happened so the inter-process code between Excel and Project
is not the problem.

Assigning the first resource works as expected
Assigning the second resource does not as the task work is not incremented
Assigning the third resource increments the task work to 10.

I thick there is a bug here, but you can get around it by:
Assign a fourth resource (create a temporary, dummy resource if necessary)
then delete the fourth resource and the end result is accurate. You can test
this manually.

--

Rod Gill
Project MVP

NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com
 
L

Leif Ingar Iversen

Rod said:
Hi,

There does look to be a bug here. I re-did the macro to run in Project and
the bug still happened so the inter-process code between Excel and Project
is not the problem.

Assigning the first resource works as expected
Assigning the second resource does not as the task work is not incremented
Assigning the third resource increments the task work to 10.

I thick there is a bug here, but you can get around it by:
Assign a fourth resource (create a temporary, dummy resource if necessary)
then delete the fourth resource and the end result is accurate. You can test
this manually.

--

Rod Gill
Project MVP

NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com

Thanks - that's great news for us!

We added your workaround to our code and it seems to work just fine.

Best Regards
Leif Ingar Iversen
IFS Research & Development
http://www.ifsworld.com
 

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