PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins Prompt a msgbox and try to cancel a close action

Reply

Prompt a msgbox and try to cancel a close action

 
Thread Tools Rate Thread
Old 21-06-2004, 05:35 PM   #1
song
Guest
 
Posts: n/a
Default Prompt a msgbox and try to cancel a close action


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


  Reply With Quote
Old 21-06-2004, 05:45 PM   #2
song
Guest
 
Posts: n/a
Default Re: Prompt a msgbox and try to cancel a close action

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

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

Thanks

"song" <gray_song@yahoo.com> wrote in message
news:ObBfm36VEHA.3740@TK2MSFTNGP12.phx.gbl...
> 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
>
>



  Reply With Quote
Old 22-06-2004, 02:47 PM   #3
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Prompt a msgbox and try to cancel a close action

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"song" <gray_song@yahoo.com> wrote in message
news:ui4q786VEHA.2928@tk2msftngp13.phx.gbl...
> Sorry, the question is partly solved by change cbYes to vbCancel.
>
> However, sometimes the event does not fire at all, any opinion?
>
> Thanks



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off