Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
other
informationbridge
office.intranets
office.misc
office.setup
office.xml
officeupdate
onenote
photodraw.discussion
powerpoint
producer
proj.standard&server
project
project.developer
project.pro_and_serve
project.server
project.vba
project2000
publisher
publisher.prepress
publisher.programming
publisher.webdesign
visio
visio.createshapes
visio.database.modeling
visio.dev.diagrams
visio.dev.shapesheet
visio.dev.vba
visio.dev.vc
visio.developer
visio.general
visio.installation
visio.printing
visio.software.modeling
visio.troubleshoot
  
 
date: Wed, 2 Jul 2008 00:55:24 -0700 (PDT),    group: microsoft.public.project.developer        back       


ProjectBeforeTaskChange making Project crash   
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
date: Wed, 2 Jul 2008 00:55:24 -0700 (PDT)   author:   unknown

RE: ProjectBeforeTaskChange making Project crash   
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


"matthills10@googlemail.com" wrote:

> 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
> 
> 
>
date: Wed, 2 Jul 2008 09:30:00 -0700   author:   Jack Dahlgren

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us