Good Afternoon,
I have not had much luck with Project questions here, but now that I have dug a little deeper I think I can ask a question that you may be able to help with. If any of you know of a better place to find Project VBA advice, please let me know!
This question is also gathering dust over at UA. http://www.utteraccess.com/forum/Custom-Macros-Project-20-t2022616.html
First off, I am writing a macro that is triggered when a task is updated in project. I used the code from this page as a starting point.
http://msdn.microsoft.com/en-us/library/ee...fice.12%29.aspx
The macro I wrote works well. I changed the code up a bit so that it runs each time the user sets a task to 100% complete. When the user sets a task to 100% complete, the macro pulls today's date and adds it to the custom date field (Date2).
My next challenge is to warn the user if they update start or finish dates for a task with a specific tag in a text field (Text15). This new functionality will be embedded with the previous functionality I already wrote. Here is the problem. When I need to
update a bunch of tasks, or when I update one task that changes other tasks due to links, the event is triggered for each and every task. This creates lots of message boxes that I don't need.
On the surface this makes sense because I want to know each time a task changes, but from a practicality standpoint I only need to be notified once for each group of tasks that are updated. For example, if I update one date, and linking causes 10 other dates
to change, I only want to be notified once. Similarly, if I highlight and change multiple dates I only want to get warned about it once, not once for each task.
To achieve this I think I need to access some kind of collection that represents the set of tasks that are being updated as a result of user input. This is where I need help. I am not sure how to access this information.
For your information here are the code elements I have written for the existing macro.
This section goes in "ThisProject":
EnableEvents
End Sub
</code>
This section goes in a module named "modTaskUpdate":
Sub EnableEvents()
Set TskUpdate.App = MSProject.Application
End Sub
</code>
Finally, this section goes in a Class Module named "clsTaskUpdate":
Public WithEvents App As MSProject.Application
Private Sub App_ProjectBeforeTaskChange(ByVal tsk As Task, ByVal Field As Long, ByVal NewVal As Variant, Cancel As Boolean)
'Code for managing 100% complete and Date Completed
'(This part works OK, see the next section for the code I need to modify)
If ((Field = pjTaskPercentComplete) And (NewVal = 100)) Then
'Add today's date to completed date field
'MsgBox "Adding today's date: " & Date & " to the Date2(DateCompleted) field."
tsk.Date2 = Date
End If
If ((Field = pjTaskPercentComplete) And (NewVal = 0)) Then
'Remove date from completed date field
'MsgBox "Removing date from the Date2(DateCompleted) field."
tsk.Date2 = ""
End If
'Code for managing warnings to user if PST dates will change.
' Currently this message is triggered for each task that causes a change.
' Can we only trigger this task once for each group of changed dates?
If ((Field = pjTaskStart) Or (Field = pjTaskFinish)) Then
If (insrt(tsk.Text15, "PST") <> 0) Then
MsgBox "Warning! You have changed a date that is linked to a line in the PST. As a result the PST has been automatically updated."
End If
End If
End Sub
</code>
FYI: The PST is an external Excel file that has its values automatically update via linked cells in Project.
Thank you for your time and consideration.
Please let me know if you have any questions.
Nate