Looping through records

C

Curmudgeon

Given a set of tasks:

Summary Task
Task_1 A
Task_2 X
Task_3 A
Task_4 X
Task_5 X
Task_6 A
Task_7 A
Task_8 X
Task_9 A

Needed:

set Summary Task.Date1 = Task_n.Start2 for the FIRST task with X and
Summary Task.Date2 = Task_n.Finish2 for the LAST task with X, ignoring
all other Tasks with X.

The FIRST X is simple enough, but I'm stuck on the LAST X - as I loop
through the tasks, there is no way to know whether a given X is the
LAST X, nor can you do a MovePrevious in such a recordset.

I suppose I could move up/down using SelectCellUp/Down and looking at
the ActiveCell.Task properties, but that sounds a little cumbersome.

Is there a better way? Can somebody suggest a better approach?

Thanks
Dave
 
J

Jack Dahlgren

dim t as task
dim ct as task 'child task
dim sMin as date
dim fMax as date
sMin = "1/1/2049"
fMax = "1/1/1990"
if t.summary then
for each ct in t.outlinechildren
Assuming that the X is in Text1 the following code should do it:

Sub foo()
Dim t As Task
Dim ct As Task 'child task
Dim sMin As Date
Dim fMax As Date
sMin = "1/1/2049"
fMax = "1/1/1990"
If t.Summary Then
For Each ct In t.OutlineChildren
If ct.Text1 = "X" Then
If ct.Start < sMin Then
sMin = ct.Start
t.Start2 = sMin
End If
If ct.Finish < fMax Then
fMax = ct.Finish
t.Finish2 = fMax
End If
End If
Next ct
End If
End Sub
 
J

Jack Dahlgren

Jan,

True, but does he want the "last" one or the "latest" one?
I assumed the "latest" is what he wants.

-Jack
 
C

Curmudgeon

dim t as task
dim ct as task 'child task
dim sMin as date
dim fMax as date
sMin = "1/1/2049"
fMax = "1/1/1990"
if t.summary then
for each ct in t.outlinechildren
Assuming that the X is in Text1 the following code should do it:

Sub foo()
Dim t As Task
Dim ct As Task 'child task
Dim sMin As Date
Dim fMax As Date
sMin = "1/1/2049"
fMax = "1/1/1990"
If t.Summary Then
For Each ct In t.OutlineChildren
If ct.Text1 = "X" Then
If ct.Start < sMin Then
sMin = ct.Start
t.Start2 = sMin
End If
If ct.Finish < fMax Then
fMax = ct.Finish
t.Finish2 = fMax
End If
End If
Next ct
End If
End Sub

Jack,
I think either your or Jan's approach should work. I'll give them both
a shot tomorrow.

Many thanks!
Dave
 

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