Custom Field in My Task View

P

Paul Conroy

The macro below adds the parent summary task to a task/text custom field
called "Parent Summary" {I suggest you add it to the beforesave event in the
Ent.Global}

Apologies to all VBA experts for being such a hack, please feel free to
optimise this code. I'd welcome any comments.

In my lab environment, I can add the CF "Parent Summary" to the my task
view, however it always returns a null value. I'd be interested in how this
manifests in other environments.

Dim t As Task
Dim t1 As Task
Dim pos As Integer
Dim myflag As Integer
Dim counter As Integer
Dim parentwbs As String
Dim parenttaskname As String


For Each t In ActiveProject.Tasks

'check that task is not nothing

If Not t Is Nothing Then

'find the last period in the wbs code
counter = 1
Do While counter < Len(t.WBS)
If InStr(counter, t.WBS, "1", 1) <> 0 Then
myflag = InStr(counter, t.WBS, ".", 1)
End If
counter = counter + 1
Loop

If myflag > 1 Then myflag = myflag - 1

'search for parent wbs value
parentwbs = Left(t.WBS, myflag)

For Each t1 In ActiveProject.Tasks
If Not t1 Is Nothing Then
If t1.WBS = parentwbs Then parenttaskname = t.Name
End If
Next

'set custom field to parent summary task name

If parenttaskname = "" Then parenttaskname = ActiveProject.Name

Call t.SetField(FieldNameToFieldConstant("Parent Summary"),
parenttaskname)

End If

Next
 
R

Rod Gill

Hi Paul,

It didn't come across to the My Tasks View for me either, but data displays
as expected in the Task Summary option for a Project View.

Yes that code can be trimmed! Does this do what you intend?

Sub parentSummary()
Dim Tsk As Task
For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then
If Tsk.OutlineLevel = 1 Then
Tsk.Text1 = ActiveProject.ProjectSummaryTask.Name
Else
Tsk.Text1 = Tsk.OutlineParent.Name
End If
End If
Next Tsk
End Sub

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.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