cancel=true does not work in ProjectBeforeTaskChange handeler.

P

Peter

Hi, Friends,

I have following code in an add-in for MS Project in order to prevent user
from modifying two fields, but the cancel=true causes my MS project stuck to
the cell just modified. Please give your ideal.

Private Sub applicationObject_ProjectBeforeTaskChange(
ByVal tsk As Microsoft.Office.Interop.MSProject.Task,
ByVal Field As Microsoft.Office.Interop.MSProject.PjField,
ByVal NewVal As Object,
ByRef Cancel As Boolean)
Handles applicationObject.ProjectBeforeTaskChange

If (Field = MSProject.PjField.pjTaskDuration) Then
MsgBox("In Duration")
Cancel = True
End If


If (Field = MSProject.PjField.pjTaskNumber18) Then
MsgBox("In Number18")
Cancel = True
End If

End Sub
 
R

Rod Gill

Hi,

Is this code in VB? Are you sure the routine is called? Events don't always
work in other processes. In VBA it should work fine. With a breakpoint, do
the MSProject.PjField.pjTaskDuration and field values look the same?
 
P

Peter

Hi, Sir,

Thank you for your help.

This code is in VB and the routine is called because I got the MsgBox pop-up
after I have modified duration value. After this modification, that MsgBox is
always poping up whenever I want to move to other cell even I change the
duration back to original value. So, I stuck to that cell and I have to kill
the MS Project.

I use Project 2003 in window XP.

Thanks.

Peter
 
B

Bill Bordiuk

Add:

SendKeys "{ESC}"

after the Cancel = True. This simulates the escape key you should use to
clear the edit (as opposed to changing the duration back, which will, of
course, trigger the event again).

Bill B
 
P

Peter

Hi, Bill,

Thank you for your ideal. I am working on an Add-in writen in VB.Net 2003 so
I have tested
SendKeys "{ESC}" Equivalent --
System.Windows.Forms.SendKeys.SendWait("{ESC}").

I have added it before and after Cancel=true. However, it does not solve my
problem. Any suggestionwill be very appriciated.

Thanks.

Peter
 
R

Rod Gill

I think sending ESC works in VBA so you have a .net problem!

As a rule it is best to get code working in VBA first to test your interface
with Project and then convert to VB.Net afterwards. This is another reason
why VB.Net is faster to code in that any of the other .net languages when
interfacing with an Office application.
 

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