Results 1 to 4 of 4

Thread: Canceling Form Unload ***Resolved***

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved Canceling Form Unload ***Resolved***

    Would I use the following code to prevent a form from unloading when the user click the red 'X' in the upper right hand corner of the form:

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.      Cancel = True
    3.      Me.Hide
    4. End Sub

    Will this do the trick or should I use the Query_Unload Event?


    Thanks
    Last edited by Mark Gambo; Mar 17th, 2005 at 07:16 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Canceling Form Unload

    Both will play the game...
    QueryUnload is executed first
    and Unload is executed after it ...

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Canceling Form Unload

    Well in your case you should use the QueryUnload event since you only want to hide the form if someone clicks the X button. But if someone is shuting down Windows or you want to end the application through code you want to unload the form so your application ends properly. You can only test why your form is being unloaded in the QueryUnload event.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     If UnloadMode = vbFormControlMenu Then
    3.         'the X has been clicked or the user has pressed Alt+F4
    4.         Cancel = True
    5.         Me.Hide
    6.     End If
    7. End Sub

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Canceling Form Unload

    Joacim,
    Thanks again!!!!

    Mark
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width