Case Statement question

J

Jerry

I am trying to change font color based on the Status of a task. Here is my
case statement

Sub percent_complete()

Dim Status As String

For Each Task In ActiveProject.Tasks

Select Case Task.Status

Case Status = "Late"

SelectRow Row:=Task.ID, RowRelative:=False

Font Color:=pjGreen

Case Status = "Complete"

SelectRow Row:=Task.ID, RowRelative:=False

Font Color:=pjRed

Case Else

SelectRow Row:=Task.ID, RowRelative:=False

Font Color:=pjBlack


End Select

Next Task

End Sub

When I debug, Status remains null. What am I missing?????

Thanks

Jerry
 
J

Jan De Messemaeker

Hello,

There ar a few remarks that may help you with your code.

First, the task.status field does not contain the strings "Late" etc. Here's
the help:

Project Developer Reference
Task.Status Property
Returns the status of a specified task. Can be one of the following
PjStatusType constants: pjComplete, pjFutureTask, pjLate, pjNoData, or
pjOnSchedule. Read-only Long.
expression.Status

Return Value
PjStatusType

expression A variable that represents a Task object.

Second your syntax of the Case statement is not correct. See the corrected
code below.

Third, your code will not work whn not all tasks are displayed and in the
order.

So here's something better (not necessarily complete)

Viewapply "Gantt Chart"

Filterapply "All Tasks"

Outlineshowalltasks

For Each Tsk In ActiveProject.Tasks
If not Tsk is Nothing then

Select Case Tsk.Status
Case pjlate

SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjGreen

Case pjcomplete
SelectRow Row:=Task.ID, RowRelative:=False
Font Color:=pjRed
Case Else
SelectRow Row:=Task.ID, RowRelative:=False

Font Color:=pjBlack
End Select
End if 'Nothing
Next Tsk
Hope this helps,



--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

JulieS

Hi Jerry,

I'm by no means a VBA expert, so if my info below doesn't work, I
suggest re-posting your question to the
microsoft.public.project.developer newsgroup. (It is also available
through the web interface).

Anyway, to my guess, the [Status] field displays text but its value is
actually numbers.

0 = Complete
1 = On Schedule
2 = Late
3 = Future Task

I don't have time right now to test your code replacing the
appropriate comments, but give it a try and see if that works.

I hope this helps. Let us know how you get along.

Julie
Project MVP

Visit http://project.mvps.org/ for the FAQs and additional information
about Microsoft Project
 
J

Jerry

That helps a lot! Thank you!

Jan De Messemaeker said:
Hello,

There ar a few remarks that may help you with your code.

First, the task.status field does not contain the strings "Late" etc. Here's
the help:

Project Developer Reference
Task.Status Property
Returns the status of a specified task. Can be one of the following
PjStatusType constants: pjComplete, pjFutureTask, pjLate, pjNoData, or
pjOnSchedule. Read-only Long.
expression.Status

Return Value
PjStatusType

expression A variable that represents a Task object.

Second your syntax of the Case statement is not correct. See the corrected
code below.

Third, your code will not work whn not all tasks are displayed and in the
order.

So here's something better (not necessarily complete)

Viewapply "Gantt Chart"

Filterapply "All Tasks"

Outlineshowalltasks

For Each Tsk In ActiveProject.Tasks
If not Tsk is Nothing then

Select Case Tsk.Status
Case pjlate

SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjGreen

Case pjcomplete
SelectRow Row:=Task.ID, RowRelative:=False
Font Color:=pjRed
Case Else
SelectRow Row:=Task.ID, RowRelative:=False

Font Color:=pjBlack
End Select
End if 'Nothing
Next Tsk
Hope this helps,



--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

JulieS

I see Jan has responded with the *correct* answer. Really, I should
know by now to just stay out of these :)
 

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