Autocalculate the contents of the Work field

F

fxs

I'd like to auto-calcuate the Work field to be equal to the sum of three
other task-level custom fields (Number type). How would I do this so that
the Work field reflects the sum as I type values into the 3 custom fields?
 
J

Jan De Messemaeker

Hi,

Since the Work field is calculated by Project it doesnt accept a formula.
It is accessible through VBA though:

loop through the tasks is a For each atask.. loop
atask.work=atak.number7+atask.number8+atask.number13
next atask

be awate that work values are interpreted as minutes by Project.
HTH
 
F

fxs

Thanks! What would that foreach statement look like?

foreach aTask in ActiveProject.Tasks??
atask.work=atak.number7+atask.number8+atask.number13
Next aTask

And, then I'm assuming that I just call this function on the click of a
custom toolbar button, or so? Correct?
 
J

Jan De Messemaeker

Hi,

I'm a bit surprised you don't know the basics of VBA while posting in the
developer newsgroup.
You have to program a procedure in VBA.
After that you can asign it to a button indeed.


Alt+F11 will show you the VB Editor.
Upper left, Select VBA Project (Global.mpt)
Insert, Module

In the upcoming code window type:

Sub TryThis()
dim atask as task
For each atask in activeproject.tasks
if not atask is nothing then
if not atask.summary then
atask.work=atask.number.... etc; depending on the number fields yopu use
atask.work=60*atask.work 'if the number foields are in hours
end if
end if
next atask
end sub

Run it through Tools, Macro, Macros to check whether that is what you want.
I suppose you know what can happen to antask when you change Work.

HTH
 

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