Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Project 2010 - Event Handler is Called, Regardless of Initiating Project

$
0
0

This one may have an obvious answer but I haven't stumbled upon it.

I have found that if you have project open with an event handler and another project open that does not an event handler, the event handler from the first project is called when an event in the second project occurs. For example, say ProjA is open and has a ProjectBeforeTaskChange event. ProjB is open and it does not have that event. When you change a task in ProjB, ProJA's ProjectBeforeTaskChange code is called. Detailed steps to reproduce may be found at the end of this post.

I can detect when this occurs and screen out the unwanted calls within the event handler. However, I'd rather not have to do that. Am I doing something wrong in the way the events are set up, or is this standard behaviour for Project 2010?

Thanks,

Paul

--------------------------------------------------------

Steps to Reproduce:

1. Create a new project

2. In the VB editor, insert the following in the new project's ThisProject module:

Option Explicit

Private Sub Project_Open(ByVal pj As Project)
    EnableEvents
End Sub

3. In the VB editor; create a new module named modTskEvnt; contents as follows:

Option Explicit

Public TskEvnt As New clsTskEvnt

Sub EnableEvents()
    Set TskEvnt.ProjApp = MSProject.Application
End Sub

4. In the VB editor, create a class named clsTskEvnt; contents as follows:

Option Explicit

Public WithEvents ProjApp As MSProject.Application

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

    If Field = pjTaskName Then
        MsgBox "Task Change - macro is from: TestEvents1", vbOKOnly
    End If
End Sub

4. Save the project as "TestEvents1.mpp"

5. Create and save a new project called "TestEvents2.mpp". This project should NOT have any macros.

6. Close and reopen TestEvent1.mpp and TestEvent2.mpp.

7. In TestEvent2.mpp, change the Task Name column for any task. You'll see that ProjectBeforeTaskChange from TestEvent1 was fired.


Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>