Results 1 to 6 of 6

Thread: Cancel Unload

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Location
    Bentonville, AR
    Posts
    22

    Cancel Unload

    Here's what I've got
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. Cancel = True
    3. End Sub

    Problem is, it closes any child forms even though it doesn't close the main form.

    Is there a solution?

    cory

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Cancel Unload

    Try setting Cancel = True in the form's QueryUnload event instead.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Cancel Unload

    What pnish said will work but you will have to do some 'IFing' or it will be impossible to close the application if you do only that.

  4. #4
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Cancel Unload

    Welcome to the forums...

    try this...

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. Cancel = 1 'Change True to 1
    3. End Sub
    Last edited by modpluz; Nov 25th, 2005 at 06:23 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Cancel Unload

    Quote Originally Posted by modpluz
    try this...

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. Cancel = 1 'Change True to 1
    3. End Sub
    Cancel can be any non-zero value. So Cancel = 1 will work exactly the same as Cancel = True (True = -1). If you wanted you could make Cancel = 12345 and it would work.

    As I posted earlier, the solution is move the code to the QueryUnload event.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Location
    Bentonville, AR
    Posts
    22

    Re: Cancel Unload

    Hey Guys,

    Thanks for the help. It works great. I didn't even notice the QueryUnload event.

    Thanks again,

    Cory

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