sorry
I did not put it clearly
I am fresh new to VBA. I think it is my code problem, that is why I post my
issue here.
now I put my code here, and thank you for advice:
' our requirement:
' if a task is required, you cannot delete it
' if a summary has a required task, you cannot delete the whole summary task
Public WithEvents App As Application
'check if a summary task has a required task
Private Function checkHasRequiredTask(sumTsk As task) As Boolean
checkHasRequiredTask = False
Dim childTsk As task
For Each childTsk In sumTak.OutlineChildren
If (Len(childTsk.Text19) > 0 And childTsk.Text19 = "false") Then
checkHasRequiredTask = True
Exit Function
End If
Next
End Function
'Occurs before a task is deleted
Private Sub app_ProjectBeforeTaskDelete(ByVal tsk As task, Cancel As Boolean)
On Error Resume Next
If tsk Is Nothing Then
Exit Sub
End If
' check if a task is required, if it is, you cannot delete it
If (Len(tsk.Text19) > 0 And tsk.Text19 = "false") Then
Cancel = True
MsgBox "You cannot delete a required task.", vbExclamation
End If
If (tsk.Summary) Then
If (checkHasRequiredTask(tsk) = True) Then
Cancel = True
MsgBox "Summary task has a required sub task. You cannot delete a
required task.", vbExclamation
End If
End If
On Error GoTo 0
End Sub
My code issue is: when you delete a required task, it works ok
but when you delete a summary that has 2 required tasks and a non-required
task, it gives msgs:
" (msg given by MS project itself saying it is a summary task, do you still
want to delete it or cancle?) "
"Summary task has a required sub task. You cannot delete a required task."
"You cannot delete a required task."
"You cannot delete a required task."
" (msg given by Ms project saying task has some actual value, do you still
want to delete it? ) "
Finally, the suammry task and the required task are still there, cannot be
deleted, and the non-required task is gone.
what I do not like it "You cannot delete a required task." will appear
twice since I have 2 required tasks, and even more if I have more required
tasks in a summary task.
But I have to keep the "You cannot delete a required task." msg for
sometimes I delete a required task.