Prompt a msgbox and try to cancel a close action

  • Thread starter Thread starter song
  • Start date Start date
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
 
Sorry, the question is partly solved by change cbYes to vbCancel.

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

Thanks
 
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.
 
Back
Top