[RESOLVED] VB 6.0 Upon Exiting a Program (Are you sure Message Box)
:wave: Hi to the VB masters.
I'm using VB 6.0 and I know this is an easy question, but my textbook doesn't cover it. I was sick the day our professor went over it. He wants us to create an |Are you sure you wish to quit?| message box connected to the Exit command button with Yes and No command buttons on it.
He also wants us to include an image of the ! on the message box, not in text but as an image, and I can't find it anywhere in our textbook. Is this something I have to set up a separate form for, or is it simply code?
No hurry it isn't due until Wednesday evening but any help you could provide would be invaluable to me.
Thanks in advance.
Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)
VB Code:
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Are you sure you want to exit ?", vbExclamation + vbYesNo) = vbNo Then
Cancel = 1
End If
End Sub
Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)
Assuming your exit button is called cmdExit...
VB Code:
Private Sub cmdExit_Click()
If MsgBox("Are you sure you want to exit?", vbExclamation + vbYesNo) = vbNo Then
Exit Sub
End If
Unload me
End Sub
Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)
you can put it in the form unload sub too
Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)
I think you need a combination of Deepak and Martin's solutions.
Deepak's suggestion will show the message box when the form tries to close, however this occurs (either from the X button on the title bar, or from one of your own buttons)
Martin's suggestion shows how to unload a form from one of your own buttons.
I'd suggest keeping the Unload Me in Martin's button and letting Deepak's code take care of the message box.
Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)
Thank you all very very much. I will be sure and mark this topic "Resolved!" Many thanks for stopping into the new guy topic.