Create a MS Project file with correct task hierarchy using Visual Basic?

E

Eugene Rokhlin

Hi All,

I have got a recordset that keeps some information that needs to be
converted to the MS Project file.

The fields are like these:
- ProjectTaskID
- ProjectTaskParentID
- WBS
- ParentWBS
- TaskName
- StartDate
- EndDate
- .... other non important fields.

What I need to do is to create a .mpp file with correct hierarchy.
So, I know a parent (if any) for every task.

What can I do?

I can open an empty .mpp file. I can add all tasks there. I try then to go
through all the tasks and set a parent for each one. But I can't see the way
to do it.

Do I need to make a task a child or parent of another task at the same time
I add it to the project or is there some way to do it later?

Can I get the task object by its ID or UniqueID?

The hierarchy of tasks can be 3 or more levels deep ....

Thanks.

Best Regards,
Eugene Rokhlin
 
G

Gérard DUCOURET

Hello Eugene,
I think that the ID and the WBS index for each task would be enough to create your hierarchy.

Gérard Ducouret
 
E

Eugene Rokhlin

Gérard DUCOURET said:
Hello Eugene,
I think that the ID and the WBS index for each task would be enough to create your hierarchy.

Gérard Ducouret

Thanks for the answer, but the first thing I tried looked like the
following

Do While Not rs.EOF

Set objTask = m_objActiveProj.Tasks.Add

objTask.Name = rs.Fields("Description")
objTask.WBS = rs.Fields("WBS")

objTask.ActualStart = Format(rs.Fields("dtSchedStartDate"),
"dd mmm yyyy")
objTask.ActualFinish = Format(rs.Fields("dtSchedEndDate"),
"dd mmm yyyy")

.........

Call rs.MoveNext
Loop

The tasks were added to the project file, but the WBS field was not shown
when I opened the .mpp file and, what is more important, there was no
hierarchy in the project.

What is missing here?

Thanks.

Best Regards,
Eugene Rokhlin
 
G

Gérard DUCOURET

Hi Eugene,
Sorry, my WBS Index was not a good idea. The best way is to use the Outline Level field.
Something like that :
SetTaskField Field:="Outline Level", Value:="2"
or
SetField... pjTaskOutlineLevel...Value:=...

Gérard Ducouret
 
S

Sarah

Eugene,

By "parent" and "child" tasks, I'm not sure if you mean through links
or subtasks, but both are easily accomplished.

If the parent task is made up of child tasks, the parent task would be
a summary task and the child tasks would be subtasks. To show this
relationship, select all of the child tasks and click the Indent arrow
on the Formatting toolbar. This pushes the child tasks in one level
under the parent task, which then shows a summary of the information
contained in the subtasks.

If the parent task is a predecessor to the child tasks, you need to
link them together. Select the predecessor (parent) task, then CTRL
click the successor (child) task, and click the Link Tasks button on
the Standard toolbar, or go to Edit>Link Tasks.

Hope this helps!
Sarah
 
E

Eugene Rokhlin

Solved this one. That's a little tricky, but it is working so far.

=====================
Do While Not rs.EOF

'If the task has no parent we are just adding a new one
If rs.Fields("ProjectTaskParentID") = -1 Then

Set objTask = m_objActiveProj.Tasks.Add
'(rs.Fields("Description"))

With objTask
.Name = rs.Fields("Description")
.WBS = rs.Fields("WBS")
..................
'Need to store the task's database id for later use
.Number1 = rs.Fields("ProjectTaskID")
End With

Else

'If a task has a parent, need to insert a task after the parent
'That is before the next task after parent
For Each objTask In m_objActiveProj.Tasks
'Search for the parent looking at the Number1 field
If objTask.Number1 = rs.Fields("ProjectTaskParentID") Then

'Task to insert before is the next after parent
iTaskID = objTask.ID + 1
'Outline because inserting the child
iTaskOutlineLevel = objTask.OutlineLevel + 1

'Check if the task after parent exist
'if not, then just add our task to the end of task list
If iTaskID > m_objActiveProj.Tasks.Count Then
Set objTask = m_objActiveProj.Tasks.Add
'Otherwise, specify position
Else
Set objTask = m_objActiveProj.Tasks.Add(, iTaskID)
End If

With objTask
.Name = rs.Fields("Description")
.WBS = rs.Fields("WBS")
.............................
.Number1 = rs.Fields("ProjectTaskID")
.OutlineLevel = iTaskOutlineLevel
End With

Exit For
End If
Next objTask

End If

rs.MoveNext

Loop

==================
 

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