Use variable for field name

S

Sean

I am trying to write a new app and want to enable the user to put values in
any text field and have the app able to pull the required info from whatever
field the user states it is in.

Example: The user, in a form, would choose that Text1 holds the data
dim t as task
dim tempfield as ???
Psuedo code:
select case userinput
case = Text1
tempfield = pjtasktext1
end select

Then later I want to alter the contents of that field
t.tempfield = "test"
So then that task would have the word "test" in text1

Is this possible?
Thanks,
Sean
 
R

Rod Gill

Yes:

dim t as task
dim tempfield as string
Psuedo code:
select case userinput
case "Text1"
tempfield = getfield(convertfieldnametofieldid(userinput),pjtask)
end select


--

Rod Gill
Microsoft MVP for Project

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




Sean said:
I am trying to write a new app and want to enable the user to put values
in
any text field and have the app able to pull the required info from
whatever
field the user states it is in.

Example: The user, in a form, would choose that Text1 holds the data
dim t as task
dim tempfield as ???
Psuedo code:
select case userinput
case = Text1
tempfield = pjtasktext1
end select

Then later I want to alter the contents of that field
t.tempfield = "test"
So then that task would have the word "test" in text1

Is this possible?
Thanks,
Sean




__________ Information from ESET Smart Security, version of virus
signature database 4516 (20091016) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4516 (20091016) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
J

Jan De Messemaeker

Hi,

This si teh help on the topic:

Application.FieldNameToFieldConstant Method
Returns a PjField constant given a field name.
Syntax

expression.FieldNameToFieldConstant(FieldName, FieldType)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
FieldName Required String The name of the field whose constant is
required.
FieldType Optional Long . The type of field. Can be one of the
following PjFieldType constants: pjResource or pjTask. The default value is
pjTask.

Return Value
PjField



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
 
R

Rod Gill

Try:

T.GetField(FieldNameToFieldConstant("Text1",pjTask))

--

Rod Gill
Microsoft MVP for Project

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




Sean said:
I tried both approaches with no luck. Rod's syntax of
convertfieldnametofieldid was not recognized as a part of the getfield
method.

When I tried Jan's help topic info I was able to get the tempfield string
to
be populated with the field ID number (some wierd 15 digit number) but
when
I tried the code t.tempfield = "Test" it did not work.






__________ Information from ESET Smart Security, version of virus
signature database 4527 (20091020) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4527 (20091020) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 

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