Trying to update task.work from VBA

I

Inge M

I am trying to update the work proerty on a task in project using VBA and
this Code

Private Sub App_ProjectBeforeTaskChange(ByVal t As Task, _
ByVal Field As PjField, _
ByVal NewVal As Variant, _
Cancel As Boolean)
Dim i As Variant
i = "100"
t.Work = i
End Sub

But i am getting a runtime error when the code is executing.

The real purpose of what want to achive is to calculate the work using two
custom fields.

t.work = number1*number2

Hope someone can help me figure out why my simple test code is not running.
 
J

Jan De Messemaeker

Hi,

Haven't tested this but quoting from previous experience (a) you have to
excluse the work field itself (ikf not you will step into an endless loop)
and (b) you cannot put work onto a summay task

So this should be better:

Private Sub App_ProjectBeforeTaskChange(ByVal t As Task, _
ByVal Field As PjField, _
ByVal NewVal As Variant, _
Cancel As Boolean)
if not t.summary then
if not field=pjtaskwork then
Dim i As Variant
i = "100"
t.Work = i
end if
endif
End Sub

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

Work is a number of minutes, not a string, so use:

dim i as integer
t.Work = i*60 '*60 if 100 is meant to be hours

Given what you said you wanted why not use:

t.work=t.number1*t.number2*60

--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

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




Jan De Messemaeker said:
Hi,

Haven't tested this but quoting from previous experience (a) you have to
excluse the work field itself (ikf not you will step into an endless loop)
and (b) you cannot put work onto a summay task

So this should be better:

Private Sub App_ProjectBeforeTaskChange(ByVal t As Task, _
ByVal Field As PjField, _
ByVal NewVal As Variant, _
Cancel As Boolean)
if not t.summary then
if not field=pjtaskwork then
Dim i As Variant
i = "100"
t.Work = i
end if
endif
End Sub

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




__________ Information from ESET Smart Security, version of virus
signature database 4929 (20100309) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4929 (20100309) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
I

Inge M

Thanks,
Your code worked like a dream.

Inge

Jan De Messemaeker said:
Hi,

Haven't tested this but quoting from previous experience (a) you have to
excluse the work field itself (ikf not you will step into an endless loop)
and (b) you cannot put work onto a summay task

So this should be better:

Private Sub App_ProjectBeforeTaskChange(ByVal t As Task, _
ByVal Field As PjField, _
ByVal NewVal As Variant, _
Cancel As Boolean)
if not t.summary then
if not field=pjtaskwork then
Dim i As Variant
i = "100"
t.Work = i
end if
endif
End Sub

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



.
 

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