Using VBA to set a value in a custom field

K

kjwass53

MS Project 2003 Pro. For each task in a project I would like to be
able to set a field
(let's say Text1) based on the contents of the Text2 fields in any
tasks that are predecessors (the immediate ones only). Can anyone
suggest a control structure for this? I know it would have something
like this in it...

Sub MySetField()
Dim MyProj As Project
Dim T As Task
MyProj = ActiveProject

For Each T In MyProj.Tasks

'if Summary task then skip

'check for predecessor tasks - if none then skip

'for each predecessor task
'check value of Text2
'logic to determine value Text1 (in the current task)
'end

' set value of Text1 in current task
End
End Sub

Thanks in anticipation,
Kevin
 
K

kjwass53

Jan - thank you for the reply - apologies I didn't make the request
clear - I think I understand the structure, what I was asking for help
was on the code that would actually make it work - my knowledge of VBA
and the object model is not that good.

Thanks,
Kevin
 
J

Jan De Messemaeker

Hi,

I personally think that that is not the normal objective of a newsgroup, but
since I like programming, here it is:

Sub MySetField()
Dim MyProj As Project
Dim T As Task
Dim Pred as task
Set MyProj = ActiveProject
For Each T In MyProj.Tasks
if not t is nothing then
If not T.summary then
if t.predecessortasks.count>0 then
for each pred in T.predecessortasks
'check value of Text2
'logic to determine value Text1 (in the current task)
next pred
end if 'predecessors
' set value of Text1 in current task e.g. T.text1=...
end if 'summary
end if 'nothing
next T

End Sub

Hope this helps,
 
K

kjwass53

Many thanks - that is exactly the help I was hoping for. Much
appreciated.

Rgds,
Kevin
 

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