|
-
Oct 22nd, 2003, 10:15 PM
#1
Thread Starter
Hyperactive Member
[Resolved]Simple: Why doesnt this on unload code work?!
I have coding that looks like:
VB Code:
Private sub Form_Unload(Cancel as Integer)
End
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
-
Oct 22nd, 2003, 10:26 PM
#2
You shouldn't use End.
This is a better approach:
VB Code:
Private Sub Command1_click()
Unload Me '(Which will envoke Form_Unload())
End Sub
Private sub Form_Unload(Cancel as Integer)
Dim objFrm As Form
For Each objFrm In Forms
Unload objFrm
Set objFrm = Nothing
Next
Cancel = False
End Sub
-
Oct 22nd, 2003, 10:32 PM
#3
It's better to place that code in Form_QueryUnload()
-
Oct 22nd, 2003, 10:35 PM
#4
Thread Starter
Hyperactive Member
bruce, your coding doesnt work.
-
Oct 22nd, 2003, 10:38 PM
#5
His code is correct. Do an F8, and see where it jumps out of the normal expected sequence of code.
-
Oct 22nd, 2003, 10:38 PM
#6
Thread Starter
Hyperactive Member
Yea, i put it in a form query unload, and it worked. Thanks for the feedback!
-
Oct 22nd, 2003, 10:40 PM
#7
That's good, but I still don't see why it wouldn't work in Form_Unload() :***:
-
Oct 22nd, 2003, 10:46 PM
#8
Thread Starter
Hyperactive Member
It's Because i have a module that does something like:
Sub Main()
Form1.Show
End Sub
Main sub is the startup object.
-
Oct 22nd, 2003, 10:47 PM
#9
Sorry, it (my original code) was in a Query_Unload Event... I just screwed up when I amalgamated it with squakMix's original code.
-
Oct 22nd, 2003, 10:49 PM
#10
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.
-
Oct 22nd, 2003, 10:49 PM
#11
Thread Starter
Hyperactive Member
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...
-
Oct 22nd, 2003, 10:50 PM
#12
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!
-
Oct 22nd, 2003, 10:53 PM
#13
Everything works for me. I hope it's something in your code, for your sake.
-
Oct 22nd, 2003, 10:59 PM
#14
Thread Starter
Hyperactive Member
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.
-
Oct 22nd, 2003, 11:28 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|