Event programming problem

D

De Smet Marc

In Project I added a new column "Number of Resources". VBA is used Event Programming and I have an EvenClassModule with the following code
Private Sub App_ProjectAssignmentNew(ByVal pj As Project, ByVal ID As Long)
ActiveCell.Task.Number2 = ActiveCell.Task.Assignments.Count
End Sub

Problems:
- when a new task is inserted somewhere between existing tasks, a blank row appears and my function generates the run time error '91' Object variable or With block variable not set. I assume this is because although a blank row is created by Project, as task has not yet been created
- when adding resources on an existing task, e.g. adding 3 different resources, my function is called 4 times, but Number2 contains 2 (it always contains 1 less than the real number of resources).
- when removing a resource name from the column "Resource Names" (or from the edit bar just above the cells) my function is not called at all.

Questions:
- How to avoid this function to run with a 'new' task (one which has not yet a task name
- What to do to get the right count (should I simple add 1: will that always work correctly?)
- How to get the function being called when directly editing the resource names (not going through Task Information)

Lots of thanks for the person(s) how can help me here.

Kind regards

Marc
 
R

Rod Gill

HI,

Try:

Private Sub App_ProjectAssignmentNew(ByVal pj As Project, ByVal ID As Long)
if not (activecell.task is Nothing) then
ActiveCell.Task.Number2 = ActiveCell.Task.Assignments.Count
End if
End Sub

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
De Smet Marc said:
In Project I added a new column "Number of Resources". VBA is used Event
Programming and I have an EvenClassModule with the following code
Private Sub App_ProjectAssignmentNew(ByVal pj As Project, ByVal ID As Long)
ActiveCell.Task.Number2 = ActiveCell.Task.Assignments.Count
End Sub

Problems:
- when a new task is inserted somewhere between existing tasks, a blank
row appears and my function generates the run time error '91' Object
variable or With block variable not set. I assume this is because although a
blank row is created by Project, as task has not yet been created
- when adding resources on an existing task, e.g. adding 3 different
resources, my function is called 4 times, but Number2 contains 2 (it always
contains 1 less than the real number of resources).
- when removing a resource name from the column "Resource Names" (or from
the edit bar just above the cells) my function is not called at all.
Questions:
- How to avoid this function to run with a 'new' task (one which has not yet a task name
- What to do to get the right count (should I simple add 1: will that always work correctly?)
- How to get the function being called when directly editing the resource
names (not going through Task Information)
 

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