Prompt a msgbox and try to cancel a close action

S

song

hi, What I want to do is to give the user a message if he does not connect
appointment to any contact and tries to close the inspector. If he choose to
cancel the close, how to cancel it?

Here is my code. But it always close, even after msgbox shows up and click
no.

Private Sub objApptItem_Close(Cancel As Boolean)
Dim myLinks As Links
On Error Resume Next
Set objApptItem = objInsp.CurrentItem
Set myLinks = objApptItem.Links
If myLinks.Count = 0 Then
If MsgBox("This appointment has no contact related, do you want to
exit?", vbOKCancel, "Appointment Exit") = vbYes Then
Cancel = True
Exit Sub
End If
End If
Cancel = False
End Sub
 
S

song

Sorry, the question is partly solved by change cbYes to vbCancel.

However, sometimes the event does not fire at all, any opinion?

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Try explicitly setting the return value from the MsgBox function to an
Integer first and then test the Integer value and see if that helps.
 

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