Ricky Baby Posted August 23, 2004 Share Posted August 23, 2004 hoe do i run some code when the X button is pressed, or how do i disable the X button and make my own quit command Link to comment Share on other sites More sharing options...
0 +Dick Montage Subscriber² Posted August 23, 2004 Subscriber² Share Posted August 23, 2004 Private Sub Form_Unload(Cancel As Integer) ? ?MsgBox ("Goodbye") End Sub OR Private Sub Form_Terminate() MsgBox ("Goodbye") End Sub ? Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 23, 2004 Member Share Posted August 23, 2004 I use VB .net, but I think it work the same anyway, Try this: Application.Exit() Link to comment Share on other sites More sharing options...
0 Ricky Baby Posted August 23, 2004 Author Share Posted August 23, 2004 njlouch = thx m8, all sorted now Link to comment Share on other sites More sharing options...
0 hash Posted August 24, 2004 Share Posted August 24, 2004 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Cancel = 1 ' Setting the Cancel flag to 1 will stop _ the Unloading of the form, and since it's _ the main form it will not end the program. ' Now you can do whatever you need to do, _ and then end the program however you want. ' Note: The UnloadMode flag may be of some _ interest to you as well. UnloadMode specifies _ why the program is ending (the form is closing) _ and the values are as follows: ' 0 - vbFormControlMenu - The user chose the Close command _ from the Control menu on the form. ' 1 - vbFormCode - The Unload statement is invoked from code. ' 2 - vbAppWindows - The current Microsoft Windows operating _ environment session is ending. ' 3 - vbAppTaskManager - The Microsoft Windows Task Manager is _ closing the application. ' 4 - vbFormMDIForm - An MDI child form is closing because the _ MDI form is closing. ' 5 - vbFormOwner - A form is closing because its owner _ is closing. ' With this information you can do whatever you need _ to do, based on how the program is being closed. ' But in any case, if you interupt the closing by _ setting the Cancel flag, you need to then close the program. ' This routine closes all forms and is the best _ way to end your program. If Cancel Then Dim f As Form For Each f In Forms Unload f Set f = Nothing Next End If End Sub Link to comment Share on other sites More sharing options...
Question
Ricky Baby
hoe do i run some code when the X button is pressed, or how do i disable the X button and make my own quit command
Link to comment
Share on other sites
4 answers to this question
Recommended Posts