Selecting the currently inserted task and subtasks

P

Prasad Basani

Hi,

I am reading task and subtask information from an Access database. I have to
insert these tasks and subtasks into Project. I am using the following code
to insert a new task and set the font and then a subtask.

Dim newTask As Task
Set newTask = ActiveProject.Tasks.Add(rs!TaskName)
newTask.Number1 = rs!ProjectID
SelectRow Row:=3, RowRelative:=False
Font Name:="Arial", Size:=8, Bold:=True, Color:=pjGreen

Dim subTask As Task
Set subTask = ActiveProject.Tasks.Add("SubTask")
subTask.OutlineIndent
subTask.Start = CDate(rs!InqDate)
subTask.Milestone = True

My newly inserted task is the 3rd row from the top in the .mpp file. That is
the reason why I used Row:=3 in the SelectRow method. But the problem is I
don't know this value at runtime. I tried newTask.ID and newTask.UniqueID but
those do not represent the position (=3) of the newly inserted task. So, I
have to know the position of this row from the top when I insert this row.

Also, I have to set the GanttBarStyle for the subtask. I think I can do this
only after selecting the subTask.

Is there any better way to achieve this? Any help is appreciated!

Thanks
Prasad
 
J

Jan De Messemaeker

Hi Prasad,

Unless you have a filter, a group, or a sort applied, newtask.ID WILL give
the row where the new task is.

You do not set a Gantt Bar "Style" to a task. In your case, the "Style" will
be the style defined for milestone tasks.
If your idea is to reformat a single bar, the GanttBarFormat method works
from the ID, not the position:

expression .GanttBarFormat(TaskID, GanttStyle, StartShape, StartType,
StartColor, MiddleShape, MiddlePattern, MiddleColor, EndShape, EndType,
EndColor, LeftText, RightText, TopText, BottomText, InsideText, Reset,
ProjectName)

Hope this helps,
 

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