ProjectBeforeTaskChange making Project crash


M

matthills10

Hi,

Using Project 2000 Standard, I'm trying to set task fields (one text
and one flag) whenever a task is changed or inserted, so am using the
ProjectBeforeTaskChange event.

I've set this up following the help text, so I have:

Created a new class module called EventClassModule, containing:

Public WithEvents App As Application

I'm connecting to this in my project using:

Dim X as New EventClassModule

Sub InitializeApp()
Set X.App=Application
End Sub

I call InitializeApp from the Project_Open event.

I then want to store the project's title in each new task's Text10
field, so use the following:

Private Sub App_ProjectBeforeTaskChange(ByVal tsk As Task, ByVal Field
As PjField, ByVal NewVal As Variant, Cancel As Boolean)

If Field=pjTaskName Then

tsk.Text10 = ActiveProject.BuiltinDocumentProperties("Title")

End If

End Sub

This works fine. I then want to flag the task as a milestone if it
appears in a certain section of the plan, so have amended the above
to:

Private Sub App_ProjectBeforeTaskChange(ByVal tsk As Task, ByVal Field
As PjField, ByVal NewVal As Variant, Cancel As Boolean)

If Field = pjTaskName And (tsk.OutlineParent.Name = "Work Package
Outputs (Deliverables)") Then
tsk.Milestone = "Yes"

Else

tsk.Text10 = ActiveProject.BuiltinDocumentProperties("Title")

End If
End Sub

This causes the follwoing behaviour:

1. If I stick to adding and changing tasks, everything works fine and
does what I want.
2. As soon as I do anthing else, like try to change the project's
properties or set an option, Project crashes. No errors, no nothing -
it just closes completely with no warning.

I assume I'm doing something really stupid? Can anyone please put me
right?

Many thanks in advance,

Matt
 
Ad

Advertisements

J

Jack Dahlgren

First thing I'd do is look at the code that causes the crash.
The first thing I'd do is change the part that says tsk.Milestone = "Yes" to
tsk.Milestone = True

If that works you are done.
If it doesn't, then comment it out or put some sort of debug statement in
there. Some people use debug.print but with events I often just use a msgbox
statement.

If your code makes it to that point then you know everything up to that
point is working.

So if it doesn't make it there, check earlier.

Can you get the if statement to work outside of an event? Just put it in a
simple macro and see what happens. In this case you can't check the field,
but all the rest can be run on a specific task:

Sub foo()
set tsk = activeproject.tasks(1)
If (tsk.OutlineParent.Name = "Work Package
Outputs (Deliverables)") Then
tsk.Milestone = "Yes"

Else

tsk.Text10 = ActiveProject.BuiltinDocumentProperties("Title")

End If
End Sub



If that works, then the problem may be with the Field statement.

-Jack Dahlgren
 

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