Assign Values to a EnterpriseProjectNumber

T

TroyS

In a macro, i'm trying to sum up a task level number (EnterpriseNumber1) and
then assign it to a Project Level Number (EnterpriseProjectNumber1)
The Summing works correctly, but i can't assign the sum to
EnterpriseProjectNumber1...any ideas?

Dim T As Task ' Task object used in For Each loop
Dim AuthorizedSum As Integer ' Count of Authorized Releases
AuthorizedSum = 0

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Line1:
Next T

'Put ApprovedSum to Project Enterprise Number1
'T.EnterpriseProjectNumber1 = AuthorizedSum
Debug.Print AuthorizedSum & " = AuthorizedSum"

'T.EnterpriseProjectNumber1 = AuthorizedSum

End Sub
 
J

John

TroyS said:
In a macro, i'm trying to sum up a task level number (EnterpriseNumber1) and
then assign it to a Project Level Number (EnterpriseProjectNumber1)
The Summing works correctly, but i can't assign the sum to
EnterpriseProjectNumber1...any ideas?

Dim T As Task ' Task object used in For Each loop
Dim AuthorizedSum As Integer ' Count of Authorized Releases
AuthorizedSum = 0

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Line1:
Next T

'Put ApprovedSum to Project Enterprise Number1
'T.EnterpriseProjectNumber1 = AuthorizedSum
Debug.Print AuthorizedSum & " = AuthorizedSum"

'T.EnterpriseProjectNumber1 = AuthorizedSum

End Sub

TroyS,
Just for your reference I couldn't set the EnterpriseProject properties
either even though the VBA help file says the property is read/write. My
guess is one of two things, (a) the VBA help file lies (its not the
first time), or (b) EnterpriseProject values must be set at Server level
or with administrator privileges. I'll query my fellow MVPs who have
more Server knowledge.

Meanwhile there are a couple of issues with the code you have shown.
First, the GoTo statement is unnecessary. The following structure is
standard format:

For Each T In ActiveProject.Tasks
If not T Is Nothing Then
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Next T

Second, even if the EnterpriseProject property could be set your code
would fail with a run time error of "missing object". The line,
"T.EnterpriseProjectNumber1 = AuthorizedSum" is outside the loop where
"T" exists (i.e. there is no longer a "T" object). The following might
be what you really want:
ActiveProject.Tasks(1).EnterpriseProjectNumber1 = AuthorizedSum

Hope this helps.
John
Project MVP
 
R

Rod Gill

Hi,

EnterpriseProjectNumber1 belongs to a project and can't be accessed from a
task.

So, try Activeproject.Project SummaryTask.EnterpriseProjectNumber1
In addition, T may not point to a task after the loop has completed: another
cause of failure.

On another note, the Goto statement below is redundant and may well cause
all sorts of unintended bugs as you maintain the software. Use the following
instead:

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Next T
 
R

Rod Gill

Hi,

Sorry, the code should be:

For Each T In ActiveProject.Tasks
If Not (T Is Nothing) Then
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Next T
 
J

John

Rod Gill said:
Hi,

EnterpriseProjectNumber1 belongs to a project and can't be accessed from a
task.

So, try Activeproject.Project SummaryTask.EnterpriseProjectNumber1
In addition, T may not point to a task after the loop has completed: another
cause of failure.

On another note, the Goto statement below is redundant and may well cause
all sorts of unintended bugs as you maintain the software. Use the following
instead:

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
AuthorizedSum = AuthorizedSum + T.EnterpriseNumber2
End If
Next T


--

Rod Gill
Project MVP
Visit www.msproject-systems.com for Project Companion Tools and more
P

Rod,
OK, then I have two questions.
1. Why does the VBA help file state that the EnterpriseProjectNumbern
Property applies to a Task object or Tasks Collection object?
2. Why does the following NOT fail
Print ActiveProject.Tasks(n).EnterpriseProjectNumbern?

Curses! Foiled again by misinformation in the VBA help file.

John
 
R

Rod Gill

1) Don't get me started on the help system as a whole: especially search!!!

2) I don' think it should work, unless you use
Print ActiveProject.Tasks(0).EnterpriseProjectNumbern
For tasks>0
Print ActiveProject.Tasks(1).EnterpriseTaskNumbern should be used.

Task zero is the Project Summary task which is still considered a task,
albeit a special task.
 
J

John

Rod Gill said:
1) Don't get me started on the help system as a whole: especially search!!!

2) I don' think it should work, unless you use
Print ActiveProject.Tasks(0).EnterpriseProjectNumbern
For tasks>0
Print ActiveProject.Tasks(1).EnterpriseTaskNumbern should be used.


Rod,
I agree the VBA help file can be very frustrating because of all the
errors and misinformation :-(

And unfortuantely, what led me astray was the fact that
ActiveProject.Tasks(n).EnterpriseProjectNumbern, where n > 0 DOES work.

Hell of a way to run a railroad in my view.

John
 

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