Addressing Task Field Names in VBA

S

SpaceCamel

Is is possible to address a task field name in VBA using the given custom name?
If "text1" is renamed "Area", is is possible to use "Area" to get at the
value?
How can I get the given name of a field name?

Also is it possible to loop thru "Textx" fields in a VBA macro with out
having to spell out each one? like:
for x=1 to 10
msgbox "Text" & x .value
next
???
 
M

Mark Durrenberger

No I'm afraid you must address the field as "Text1",
At the moment, I can't think of how to loop through the text columns -
perhaps the getfield method...

Mark
--
_________________________________________________________
Mark Durrenberger, PMP
Principal, Oak Associates, Inc, www.oakinc.com
"Advancing the Theory and Practice of Project Management"
________________________________________________________

The nicest thing about NOT planning is that failure
comes as a complete surprise and is not preceded by
a period of worry and depression.

- Sir John Harvey-Jones
 
S

SpaceCamel

I figured it out myself. I used the CustomFieldGetName function using the
numeric value for the text field. The GetField will work to get the value
but I am using the CallByName function. This is a lot more compact then
using a bunch of if-then or case statements.

Set myTasks = myProj.Tasks
Set myTask = myTasks(7)

fldno = 188743731 'pjTaskText1
For i = 1 To 10
CustName = pj.Application.CustomFieldGetName(fldno)
'myValue = myTask.GetField(fldno)
myfield = "Text" & i
myValue = CallByName(myTask, myfield, VbGet)

MsgBox myfield & ":" & CustName & " :" & myValue
fldno = fldno + 3
Next
================================================
 
E

Earl Lewis

SpaceCamel,

Instead of getting that messy long number hard-coded in your routine you can use the constant for it, i.e. pjCustomTaskText1. This might protect you a little in the version upgrade process later on.

Earl
I figured it out myself. I used the CustomFieldGetName function using the
numeric value for the text field. The GetField will work to get the value
but I am using the CallByName function. This is a lot more compact then
using a bunch of if-then or case statements.

Set myTasks = myProj.Tasks
Set myTask = myTasks(7)

fldno = 188743731 'pjTaskText1
For i = 1 To 10
CustName = pj.Application.CustomFieldGetName(fldno)
'myValue = myTask.GetField(fldno)
myfield = "Text" & i
myValue = CallByName(myTask, myfield, VbGet)

MsgBox myfield & ":" & CustName & " :" & myValue
fldno = fldno + 3
Next
================================================
 
R

Rod Gill

Hi,

In 2002 and 2003 you can use the FieldNameToFieldConstant function. So,

Dim i as integer
for i=1 to 30
Activeproject.tasks(1).GetField(FieldNameToFieldConstant("Text"& i))
next i

should work.
--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.project-systems.co.nz/
Email rodg AT project-systems DOT co DOT nz
 
S

SpaceCamel

Thanks Rod, That works better.

For i = 1 To 30
myfield = "Text" & i
fldno = FieldNameToFieldConstant(myfield)
myValue = myTask.GetField(fldno)
'myValue = CallByName(myTask, myfield, VbGet)
CustName = pj.Application.CustomFieldGetName(fldno)

'MsgBox myfield & ":" & CustName & " :" & myValue
Next
=========================
 

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