Application.ProjectBeforeTaskChange event (Project)
Occurs before the user changes the value of a task field.
Syntax
expression. ProjectBeforeTaskChange
( _tsk_
, _Field_
, _NewVal_
, _Cancel_
)
expression A variable that represents an Application object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
tsk | Required | Task | The task whose field is being changed. |
Field | Required | Long | The field being changed. If more than one field is changed by the user, the event is fired for each field changed. Can be one of the PjField constants. |
NewVal | Required | Variant | The new value for the field specified with Field. |
Cancel | Required | Boolean | False when the event occurs. If the event procedure sets this argument to True, the value for the field specified with Field is not changed. |
Remarks
Project events don't occur when the project is embedded in another document or application.
The ProjectBeforeTaskChange event doesn't occur when timescaled data changes, when constraint data in the Task Details Form changes, when a task is split by manipulating its task bar on the Gantt Chart, when changes are made to outline level or outline number, when a baseline is saved, when a baseline is cleared, when an entire task row is pasted, during resource pool operations, when inserting or removing a subproject, or when changes have been made using a custom form. For more information and sample code for creating and testing an event handler, see Using Events with Application and Project Objects.
Example
The following example informs the user when the duration of a task increases and by how much. This example requires a new class module and additional code for it to have an effect.
Private Sub App_ProjectBeforeTaskChange(ByVal tsk As Task, ByVal Field As PjField, _
ByVal NewVal As Variant, Cancel As Boolean)
Dim TaskDuration As Long
TaskDuration = Val(NewVal) * 480 ' Convert days to minutes
If Field = pjTaskDuration And TaskDuration > tsk.Duration Then
If (TaskDuration - tsk.Duration) \ 480 < 1 Then
MsgBox "The task " & Chr$(34) & tsk.Name & Chr$(34) & " is now " & _
(TaskDuration - tsk.Duration) / 480 & (TaskDuration - tsk.Duration) \ 480 & _
" day(s) longer."
Else
MsgBox "The task " & Chr$(34) & tsk.Name & Chr$(34) & " is now " & _
(TaskDuration - tsk.Duration) / 480 & " day(s) longer."
End If
End If
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.