I am currently trying to use a ProjectBeforeAssignmentChange application in a class module to pull resource and assignment costs into a task field. I am doing this because I want to group resource loads on a task into labor and material buckets. I have received some great guidance on how to use a ProjectBeforeAssignmentChange application to isolate an assignment change and react to it. I am now trying to make a link between this application and the ability to parse and sum data in a task.Cost# field.
Currently, the class module prints a lot of helpful information into the immediate window. Can someone please recommend how to sum Cost = Assgn.Cost
as it loops and route it to tsk.Cost5 (for my purposes)? I have tested multiple approaches to this problem and all failed. It appears that the assignment change event does not acknowledge task objects.
ThisProject:
Private Sub Project_Open(ByVal pj As Project)
Call m_Events.StartEvents
End Sub
m_Event as a regular module:
Public oMSPEvents As New cm_Events
Public EnableEvents As Boolean
Sub StartEvents()
Set oMSPEvents.MyMSPApp = Application ' MSProject.Application
EnableEvents = True
End Sub
cm_Events Class Module:
Private Sub MyMSPApp_ProjectBeforeAssignmentChange(ByVal Assgn As Assignment, ByVal Field As PjAssignmentField, ByVal NewVal As Variant, Cancel As Boolean)
'
'Dim tsk As task
If Assgn.Resource.Text2 = "Labor" Then
Cost = Assgn.Cost
Debug.Print Now, Assgn.ResourceName, Assgn.Resource.Text2, NewVal, "$" & Cost, Assgn
End If
If EnableEvents Then
EnableEvents = False
' tsk.Cost5 = 10
'
' Dim Assgn As Assignment
' For Each Assgn In tsk.Assignments
' If Assgn.Resource.Text1 = "Labor" Then
' tsk.Cost5 = tsk.Cost5 + Assgn.Cost
' Assgn.Cost5 = Assgn.Cost5 + Assgn.Cost
' End If
' Next Assgn
'
EnableEvents = True
End If
End Sub
Take a look at this Wiki article. It will show you how to do it. https://social.tec.net.microsoft.com/wiki/contents/articles/32051.ms-project-extra-fields-in-views.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.