Passing/using column name as parameter?

C

Carl

I have a macro I like that keys off of data in Text1. I would like to
generalize it so that I can pass in the column that drives report generation.
I would like to do something like:

Dim RptFld as string

RptFld = "Text2"

For Each Tsk In ActiveSelection.Tasks
If Not Tsk Is Nothing
Debug.Print Tsk.RptFld
End If
Next Tsk

How do I get the value of RptFld used so that the Debug.Print statement will
print the contents of Text2?

-- Carl
 
J

John

Carl said:
I have a macro I like that keys off of data in Text1. I would like to
generalize it so that I can pass in the column that drives report generation.
I would like to do something like:

Dim RptFld as string

RptFld = "Text2"

For Each Tsk In ActiveSelection.Tasks
If Not Tsk Is Nothing
Debug.Print Tsk.RptFld
End If
Next Tsk

How do I get the value of RptFld used so that the Debug.Print statement will
print the contents of Text2?

-- Carl

Carl,
Your existing code it trying to treat the variable "RptFld", (a user
defined variable), as a property of a Task object, and that doesn't
work. Change that line in your code to be:
Debug.Print Tsk.Text2
and it should give what you want.

John
Project MVP
 
C

Carl

John,

You've homed right in on the problem: I want to specify Text1, Text2, etc...
using the variable RptFld. From what I gather there is a method available in
later versions of Project that you can use in conjunction with the task's
GetField method, but alas, I have Project 2000 as one of my constraints...

-- Carl
 
R

Rod Gill

Hi,

The only way to do this is:

RptFld = "Text1"
For Each Tsk In ActiveSelection.Tasks
If Not Tsk Is Nothing Then
Debug.Print
Tsk.GetField(Application.FieldNameToFieldConstant(RptFld, pjTask))
End If
Next Tsk

FieldNameToFieldConstant is available in Project 2003, I can't remember with
2000. I don't think you can do it if not.
--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
C

Carl

Rod,

Thanks for the response. Doesn't look like it's available to me. I just
have a few values to look up, so it might make sense to do my own version of
that routine and build the code around it to make it easy to port to an
upgraded version of Project in the future.

When I was trying to do this I was thinking there might be a way to build a
command and have it interpreted at run time, kind of like how substitutions
happen before evaluation with shell scripts. But I guess all this gets
compiled for execution, so even if that were possible, it would hurt speed.

-- Carl
 

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