none
Display summary name of outline level 1 parent in text field RRS feed

  • Question

  • Hi,

    We have project 2003 server and we need to run resource assignment report in PWA. Currently some tasks name are similar in each project and it’s desirable to show the task and level 1 summary of assigned tasks. I'm looking for MS project vba/macros that will display the name of summary outline level1 of each tasks in a text field. Level 0 is our highest level.

    The difficult part is just displaying ONLY “outline level1” parent/grandparent/great grandparent etc. of each tasks. I have created macros in the past to display parent tasks and grandparent tasks but I have not been able to get result for just displaying level 1 hierarchy parent name for each tasks.

    Thank you

    Monday, December 19, 2016 5:39 PM

Answers

  • OK.  The syntax for enterprise fields is a little more complex, but it works equally well for local fields.  (I've had to use it when using variable field names.)  Unfortunately, I don't have any way to test for true enterprise fields, so if this doesn't work I'm out of solutions.

    Sub Level1InheritStartEF()
    Dim t As Task
    Dim tpname As String
    Dim StartLevel As Integer
    
    StartLevel = 1
        For Each t In ActiveProject.Tasks
            If Not t Is Nothing Then
                If t.OutlineLevel = StartLevel Then
                    tpname = t.Name
                    Call tcnamerEF(t, tpname, StartLevel)
                End If
            End If
        Next t
    End Sub
    
    Sub tcnamerEF(ByRef tc As Task, ByRef tpname As String, ByRef StartLevel As Integer)
    Dim i As Integer
        If tc.OutlineLevel = StartLevel Then
            tc.SetField Application.FieldNameToFieldConstant("Summary One"), ""
        Else
            tc.SetField Application.FieldNameToFieldConstant("Summary One"), tpname
        End If
        'Recurse to the next layer
        For i = 1 To tc.OutlineChildren.Count
            Call tcnamerEF(tc.OutlineChildren(i), tpname, StartLevel)
        Next i
    End Sub
    
    Good Luck, t

    • Marked as answer by Tonyson Wednesday, December 21, 2016 8:19 PM
    Wednesday, December 21, 2016 1:56 AM

All replies

  • How does this work for you?

    The first sub just finds the level 1 tasks and calls the second sub.  The second sub recursively assigns the name of each Level 1 Task to the Text1 field of all its decendents. 

    Maybe not optimized, but it would seem to work....

    Option Explicit
    
    Sub Level1InheritStart()
    Dim t As Task
    Dim tpname As String
    Dim StartLevel As Integer
    
    StartLevel = 1
        For Each t In ActiveProject.Tasks
            If Not t Is Nothing Then
                If t.OutlineLevel = StartLevel Then
                    tpname = t.Name
                    Call tcnamer(t, tpname, StartLevel)
                End If
            End If
        Next t
    End Sub
    
    
    Sub tcnamer(ByRef tc As Task, ByRef tpname As String, ByRef StartLevel As Integer)
    Dim i As Integer
        If tc.OutlineLevel = StartLevel Then
            tc.Text1 = ""
        Else
            tc.Text1 = tpname
        End If
        'Recurse to the next layer
        For i = 1 To tc.OutlineChildren.Count
            Call tcnamer(tc.OutlineChildren(i), tpname, StartLevel)
        Next i
    End Sub

    Monday, December 19, 2016 9:00 PM
  • Thank you Tom for your help. The vba ran great but I would like to add the result to an enterprise custom named field rather than text1 e.g a A field name 'Summary One' that is available to all enterpise user.

    Thanks

    Tuesday, December 20, 2016 9:03 PM
  • OK.  The syntax for enterprise fields is a little more complex, but it works equally well for local fields.  (I've had to use it when using variable field names.)  Unfortunately, I don't have any way to test for true enterprise fields, so if this doesn't work I'm out of solutions.

    Sub Level1InheritStartEF()
    Dim t As Task
    Dim tpname As String
    Dim StartLevel As Integer
    
    StartLevel = 1
        For Each t In ActiveProject.Tasks
            If Not t Is Nothing Then
                If t.OutlineLevel = StartLevel Then
                    tpname = t.Name
                    Call tcnamerEF(t, tpname, StartLevel)
                End If
            End If
        Next t
    End Sub
    
    Sub tcnamerEF(ByRef tc As Task, ByRef tpname As String, ByRef StartLevel As Integer)
    Dim i As Integer
        If tc.OutlineLevel = StartLevel Then
            tc.SetField Application.FieldNameToFieldConstant("Summary One"), ""
        Else
            tc.SetField Application.FieldNameToFieldConstant("Summary One"), tpname
        End If
        'Recurse to the next layer
        For i = 1 To tc.OutlineChildren.Count
            Call tcnamerEF(tc.OutlineChildren(i), tpname, StartLevel)
        Next i
    End Sub
    
    Good Luck, t

    • Marked as answer by Tonyson Wednesday, December 21, 2016 8:19 PM
    Wednesday, December 21, 2016 1:56 AM
  • Tom - It worked great!! Thank you for your help. I appreciate your time!
    Wednesday, December 21, 2016 8:25 PM