msgbox and summary issue

J

Joy

It seems in MS project, if we do sth to summary task, the same operation will
be performed on all its usb tasks. like if you delete a summary, all its
sub tasks will be gone as well.

now, I am writing a macro, it will do sth to summary task and it will give a
msg box. however, each time I do this, the msg box will appear 3 times if the
summary task has 2 children, or 10 times if the summary task has 9
children!!, or even more, if a child has children, too.

That would drive users mad!!

what I can do to let the msg appear only once???
 
J

Jack Dahlgren MVP

Show the code and we may be able to figure out why it is not working.

-Jack
 
J

John

Joy said:
It seems in MS project, if we do sth to summary task, the same operation will
be performed on all its usb tasks. like if you delete a summary, all its
sub tasks will be gone as well.

now, I am writing a macro, it will do sth to summary task and it will give a
msg box. however, each time I do this, the msg box will appear 3 times if the
summary task has 2 children, or 10 times if the summary task has 9
children!!, or even more, if a child has children, too.

That would drive users mad!!

what I can do to let the msg appear only once???

Joy,
By the way, don't forget to tell us what "sth" is.

John
Project MVP
 
J

Jan De Messemaeker

Hi,

And for the good news, whatever sth is, a message box callled for a summary
task will NOT automatically appear for the subtasks - don't worry
If it does, it's your code doing it.
HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

John

JulieS said:
something?
Julie

Julie,
One might assume that but who knows. My feeling is that "shorthand" may
be OK for text messaging but when it comes to posting on a professional
based newsgroup, posters should be clear and concise. If a poster
"doesn't have time" or is simply to lazy to write out their question so
that we don't have to guess what they mean or want, then I'm reluctant
to spend much of my time trying to help.

Sorry if my view sounds harsh. This has been a sore point with me for
years.

John
 
J

JulieS

John said:
Julie,
One might assume that but who knows. My feeling is that
"shorthand" may
be OK for text messaging but when it comes to posting on a
professional
based newsgroup, posters should be clear and concise. If a poster
"doesn't have time" or is simply to lazy to write out their
question so
that we don't have to guess what they mean or want, then I'm
reluctant
to spend much of my time trying to help.

Sorry if my view sounds harsh. This has been a sore point with me
for
years.

John

I couldn't agree with you more. Your view doesn't sound at all
harsh in my opinion.

If someone wants help, it's incumbent upon them to explain as fully
as possible what the question is. I suggest people should spend as
much time posting a question as they would like responders to take
posting the answer.

Julie
 
J

Jan De Messemaeker

Hi,

Agree. Just also remember people who even after serious explanation about
duration and work insist on using "the hours" "my hours" etc, so it's
impossible to properly even understand the question. It's a lack of respect,
if you want to help them, you're considered a servant no more..

Greetings,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

Joy

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.
 
J

Jack Dahlgren MVP

Joy,
I don't have a lot of time to debug this, but have a suggestion.

Try checking for the summary task first and exit sub with cancel = true.

Another suggestion is to set some sort of flag when it checks the task and
then at the end of all the loops it writes the message only once.

for example
' 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
reqTask = True
'Move this line outside the loop -- MsgBox "You cannot delete a required
task.", vbExclamation
End If

If (tsk.Summary) Then
If (checkHasRequiredTask(tsk) = True) Then
Cancel = True
reqSumTask = True
'move this later ----- MsgBox "Summary task has a required sub task. You
cannot delete a
required task.", vbExclamation
End If

-then when all is done try this:

if reqSumTask = true then
MsgBox "Summary task has a required sub task. You cannot delete a required
task.", vbExclamation
else if reqtask = true then
MsgBox "You cannot delete a required task.", vbExclamation
end if

It still may not work, but that is what I'd try.

-Jack Dahlgren
 

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