Results 1 to 15 of 15

Thread: [Resolved]Simple: Why doesnt this on unload code work?!

  1. #1

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342

    [Resolved]Simple: Why doesnt this on unload code work?!

    I have coding that looks like:

    VB Code:
    1. Private sub Form_Unload(Cancel as Integer)
    2. End
    3. End sub

    For some reason, when i click the close button, Nothing happends. My form's startup is main, and main calls for form1 to load. End unloads the WHOLE program. For some reason, It's just ending Form1, and Main is calling it back up. I put a close COMMAND button on it, and gave it the coding :

    Code:
    Private Sub Command1_click()
    End
    End Sub
    And it worked fine! Can i have a little help here? Thanks!
    Last edited by squakMix; Oct 22nd, 2003 at 10:39 PM.
    -squaK

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    You shouldn't use End.

    This is a better approach:
    VB Code:
    1. Private Sub Command1_click()
    2.     Unload Me '(Which will envoke Form_Unload())
    3. End Sub
    4.  
    5. Private sub Form_Unload(Cancel as Integer)
    6.     Dim objFrm As Form
    7.  
    8.     For Each objFrm In Forms
    9.         Unload objFrm
    10.         Set objFrm = Nothing
    11.     Next
    12.  
    13.     Cancel = False
    14.  
    15. End Sub

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    It's better to place that code in Form_QueryUnload()

  4. #4

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342
    bruce, your coding doesnt work.
    -squaK

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    His code is correct. Do an F8, and see where it jumps out of the normal expected sequence of code.

  6. #6

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342
    Yea, i put it in a form query unload, and it worked. Thanks for the feedback!
    -squaK

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    That's good, but I still don't see why it wouldn't work in Form_Unload() :***:

  8. #8

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342
    It's Because i have a module that does something like:
    Sub Main()
    Form1.Show
    End Sub

    Main sub is the startup object.
    -squaK

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Sorry, it (my original code) was in a Query_Unload Event... I just screwed up when I amalgamated it with squakMix's original code.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by squakMix
    It's Because i have a module that does something like:
    Sub Main()
    Form1.Show
    End Sub

    Main sub is the startup object.
    Oh NOW you tell us.

  11. #11

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342
    Wait, im wrong. your right mendhak, I dont know why it didnt work with Unload.
    Must have been something in the rest of my coding...
    -squaK

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by squakMix
    Wait, im wrong. your right mendhak, I dont know why it didnt work with Unload.
    Must have been something in the rest of my coding...
    Unloading a form might call the modules Sub Main() event. I'll just check it out and be right back.

    Wait for me. Don't move a muscle!

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Everything works for me. I hope it's something in your code, for your sake.

  14. #14

    Thread Starter
    Hyperactive Member squakMix's Avatar
    Join Date
    Oct 2003
    Location
    Washington
    Posts
    342
    OOOH, i see why. I have a loop in my Main() event... I Forgot i had that... It has to do with a system Wide hook that im initializing on Main.
    -squaK

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by squakMix
    OOOH, i see why. I have a loop in my Main() event... I Forgot i had that... It has to do with a system Wide hook that im initializing on Main.
    OH, NOW you tell us!

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