Accessing the value of a custom field in VBA

G

Glenn

I have a custom field which has numeric values. I want to take these numeric
values and assign them to their respective duration for each task.

Using this line of code I can find the duration

ActiveProject.Tasks(1).Duration

How can I extract the numeric value from my custom field and then assign it
to the task's duration as in the following code
ActiveProject.Tasks(1).Duration = VALUE OF CUSTOM
FIELD
 
J

Jan De Messemaeker

activeproject.tasks(1).duration=activeproject.tasks(1).number7

If number7 is the custom field
Attention! Duration in VBA is in minutes! Is number7??
HTH
 
G

Glenn

John,

I am using the following syntax without success, any ideas? thanks
My pjCustomTaskDuration3 is set to the custom fields value.

Dim str$

str =
MsgBox(ActiveProject.Tasks(1).CustomFieldValueListGetItem(pjCustomTaskDuration3, pjValueListValue, 0), vbOKCancel)
 
J

John

Glenn said:
I have a custom field which has numeric values. I want to take these numeric
values and assign them to their respective duration for each task.

Using this line of code I can find the duration

ActiveProject.Tasks(1).Duration

How can I extract the numeric value from my custom field and then assign it
to the task's duration as in the following code
ActiveProject.Tasks(1).Duration = VALUE OF CUSTOM
FIELD

Glenn,
Try the CustomFieldValueListGetItem Method. You can get the full syntax
by looking in the VBA help file.

Hope this helps.
John
Project MVP
 
J

John

Glenn said:
John,

I am using the following syntax without success, any ideas? thanks
My pjCustomTaskDuration3 is set to the custom fields value.

Dim str$

str =
MsgBox(ActiveProject.Tasks(1).CustomFieldValueListGetItem(pjCustomTaskDuration
3, pjValueListValue, 0), vbOKCancel)

Glenn,
It doesn't work because the CustomFieldValueListGetItem Method does not
apply to a task object. Rather, it applies to an application object.
(Look up the method in the Project VBA help file and look at the
"applies to" link). If you just want a message box to pop up with the
value, this is the syntax to use (note that an index of 0 is not valid
for a value list):
MsgBox "Value is: " & CustomFieldValueListGetItem(pjCustomTaskDuration3,
pjValueListValue, 1)

However, I think I misunderstood what you were after. Jan's reply
answers the question except for one item. As long as you are
transferring data between two duration fields you won't need to do a
conversion for minutes. True, the value in the underlying Project
database stores duration values in minutes, but the built-in formatting
of the various duration fields takes this into account. So as a bottom
line the following code will do what you want.

Sub DurValListToDur()
For each t in ActiveProject.Tasks
If Not t is Nothing Then
t.Duration = t.Duration3
End If
Next t
End Sub

Hope this helps.
John
Project MVP
 

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