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
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