|
-
Jan 10th, 2000, 03:55 AM
#1
Thread Starter
Junior Member
How can I cause VB to ask if you really want to close a form when someone clicks the X in the upper right hand corner.
-
Jan 10th, 2000, 04:02 AM
#2
Fanatic Member
This should do the job:
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim retVal As Integer
retVal = MsgBox("Are you sure you want to exit?", vbYesNo, "Exit")
If retVal = vbYes Then
Cancel = 0
Else
Cancel = 1
End If
End Sub
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
-
Jan 10th, 2000, 04:02 AM
#3
Hyperactive Member
In the form_unload event, type:
Dim Response as Byte
Response = MsgBox("Are you sure you want to close?", vbYesNo + vbInformation)
If Response = vbNo Then
Cancel = True
End If
-
Jan 10th, 2000, 04:23 AM
#4
Thread Starter
Junior Member
Thank you! Both worked great...
-
Jan 10th, 2000, 04:41 AM
#5
You'd be better off if you did the following in your form's QueryUnload event. You may not need to check for all the conditions, but you probably should at least consider if you still want to ask the user if he/she wants to exit if it's Windows or your code that is closing the form.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim retVal As Integer
Select Case UnloadMode
Case vbFormControlMenu
' The user chose the Close command from the Control menu on the form
retVal = MsgBox("Are you sure you want to exit?", vbYesNo, "Exit")
If retVal = vbYes Then
Cancel = True
End If
Case vbFormCode
' The Unload statement is invoked from code.
Case vbAppWindows
' The current Microsoft Windows operating environment session
' is ending.
Case vbAppTaskManager
' The Microsoft Windows Task Manager is closing the application.
Case vbFormMDIForm
' An MDI child form is closing because the MDI form is closing.
vbFormOwner
' A form is closing because its owner is closing.
End Select
End Sub
------------------
Marty
-
Jan 10th, 2000, 05:09 AM
#6
Thread Starter
Junior Member
Marty,
Thank you! That is what I will use as it would make sense to make sure you know what is telling the form to close.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|