Getting Column Titles

B

Buster

I am trying to get the custom field name from the text fields using

Activeproject.tasks(1).GetField(FieldNameToFieldConstant("Text"& i))

The problem I'm having is that it is returning the first value in row 1 of
the project plan?

Any ideas on how to rectify thhis?

JEff
 
G

Gord Schmidt

The GetField method returns the value in the field. You probably want the
title of the TableFields object. Try the following:

fieldNumber = InputBox$(Prompt:="Enter the number of the " _
& "column you want to center in the Entry table." _
& Chr(13) & "For example, Column 1 is the Indicators " _
& "column.")

MsgBox ("Title = " &
ActiveProject.TaskTables("Entry").TableFields(fieldNumber + 1).Title)

' See the PjField constants in the Microsoft Office Project Visual Basic
Reference
MsgBox ("Field = " &
ActiveProject.TaskTables("Entry").TableFields(fieldNumber + 1).Field)
 
D

DMS

Actually there is a method called CustomFieldGetName

You could use it like this
strCustName = CustomFieldGetName(pjCustomTaskText1)

Hope this helps
 
B

Buster

I have tried the code you supplied, but have one question, why does it fail
when I substitute "pjCustomTaskText1" with "pjCustomTaskText&i)" where i is
the variable from the for next counter so that I loop through each of the 1
to 40 fields.
 
J

John

Buster said:
I have tried the code you supplied, but have one question, why does it fail
when I substitute "pjCustomTaskText1" with "pjCustomTaskText&i)" where i is
the variable from the for next counter so that I loop through each of the 1
to 40 fields.

Jeff,
It fails because the argument in the CustomFieldGetName Method is a long
and you are trying to use a string. There are various ways to handle
this.

One method that sometimes works is use the long numerical value. For
example, use 188743731 instead of pjCustomTaskText1. This method works
best if the numerical values for each of the fields of interest are
sequential (or nearly so). Then increment the value to the next field.
Note that the difference isn't always "1" and there may be breaks in the
sequence so those will have to be addressed. Another downside is that by
using the numerical value, it is not obvious which field is being
addressed.

Another method that works is to set up a case statement to change the
long constant each run through the loop. Yes it is a lot of case
statements but it gets the job done.

Hope this helps.
John
 
D

das

I was trying the following code but to no avail;
Dim pjCustomTaskText1 As String
Dim Task_Name As Long

pjCustomTaskText1 = "pjCustomTaskText" & (i)
Task_Name = pjCustomTaskText1
xlRng = CustomFieldGetName(Task_Name)
I was hoping to use the Task_Name aas long and throw in the pjfield name.
Will this approach work at all?

Jeff
 
J

John

das said:
I was trying the following code but to no avail;
Dim pjCustomTaskText1 As String
Dim Task_Name As Long

pjCustomTaskText1 = "pjCustomTaskText" & (i)
Task_Name = pjCustomTaskText1
xlRng = CustomFieldGetName(Task_Name)
I was hoping to use the Task_Name aas long and throw in the pjfield name.
Will this approach work at all?

Jeff

Jeff,
No. You will get an runtime error (type mismatch) on the line "Task_Name
= pjCustomTaskText1" because you are mixing variable types (i.e. a
declared long and a declared string). And, trying to convert the string
to a long won't work either. Why not try one of the methods I described?
They do work.

John
 
J

JackD

To add onto the explanation and solution that John has given, here is the
basic reason why.

It would work if you could convert the string into the CONSTANT that
pjCustomTaskText1 represents, but you can't do that.

pjCustomTaskText1 is the NAME of a constant. Just like Pi is the name of
3.14159....

clng("P"&"i") won't give you a value of 3.14159...

Things that start with "pj" in project are typically constants. They are
convenient ways of referring to numerical values. This is commonly done so
that you can change the names of the constants for various languages (ie: in
pig latin you might call it pjustomCayaskTayextTay1) and still leave the
rest of the application the same.
In fact if you look at the project database, the MSP_Conversions table shows
how this works and contains the conversion values if you need to look them
up. Fortunately numbers don't need to be translated.
 
B

Buster

Thanks Jack, I get the picture. So can I read the list of PJ constants from
a file and substitute the PJ value?

Jeff
 
J

JackD

Yes if you want.
I'm not sure that ALL the constants are in any particular file, but in
general, using the name or the value of the constant in the code will work
the same way. Names are easier when it comes time to debug though!
 

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