-
January 27th, 2005, 03:42 AM
#1
Procedure Executes after Unload Me Statement
Private Sub Command1_Click()
MsgBox "WelCome"
Unload Me
TestFun
End Sub
Private Sub TestFun()
MsgBox "Why does this Execute?"
End Sub
Why the Procedure TestFun Execute After the Unload Me Statement.
I dont want to execute any procedures or Statements after unload Me Statement. Pls give a Solution to this problem.
Thx in Advance.
-
January 27th, 2005, 04:01 AM
#2
Re: Procedure Executes after Unload Me Statement
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
January 27th, 2005, 04:16 AM
#3
Re: Procedure Executes after Unload Me Statement
Thx,
My Case is
Private Sub Command1_Click()
MsgBox "WelCome"
TestFun
MsgBox "Why does this Execute?"
End Sub
Private Sub TestFun()
MsgBox "TestFun Called"
Unload Me
Exit Sub
End Sub
Pls. Help me. I need not want to execute any of the Statements after the Unload me statement.
Thx in Advance.
-
January 27th, 2005, 04:42 AM
#4
Re: Procedure Executes after Unload Me Statement
Code:
Private Sub Command1_Click()
MsgBox "WelCome"
TestFun
MsgBox "Why does this Execute?"
End Sub
Private Sub TestFun()
MsgBox "TestFun Called"
Unload Me
End
End Sub
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
January 27th, 2005, 04:42 AM
#5
Re: Procedure Executes after Unload Me Statement
Code:
Private Sub Command1_Click()
MsgBox "WelCome"
TestFun 'u call tesfun procedure..after that it will popup msbox below..that's why
MsgBox "Why does this Execute?"
End Sub
Private Sub TestFun()
MsgBox "TestFun Called"
Unload Me
Exit Sub ' not really need this..
End Sub
if u don't want to be excuted then try remove the red line..if u still wish that line that add End statement at form_unload though it's not recomended..
-
January 27th, 2005, 04:52 AM
#6
Re: Procedure Executes after Unload Me Statement
Thanks
But in my case
I have Written a Procedure To insert Entries into Different Tables
Within One Procedure named
Private Sub SaveEntries()
on error goto err
SaveHeader 'Procedure to insert header table
SaveDetail 'Procedure to insert into detail table
msgbox"Entry Saved"
err:
' Rollbacktrans
end sub
Private sub SaveHeader()
on error goto err
'insert statement and other codes
err:
unload me
end sub
If Any Error Occurs in any of the Procedure saveheader or in detail then other statement or other procedure should not be executed and Form should be closed and Mdiform form should be there and not to close the whole project
pls help me
-
January 27th, 2005, 04:58 AM
#7
Re: Procedure Executes after Unload Me Statement
in that case..maybe u should use function instead of sub
something like this
Code:
private function InsertToTable As boolean
a= true
on error goto errHandle
'ur code here
exit sub 'u forgot to add this before ur errHandle
errHandle:
a = false
end function
and to use it
Code:
if InsertToTable=true then 'process other
hope u get the idea..
-
January 27th, 2005, 05:02 AM
#8
Re: Procedure Executes after Unload Me Statement
Code:
Private Sub SaveEntries()
On Error GoTo err
If SaveHeader Then 'Procedure to insert header table
SaveDetail 'Procedure to insert into detail table
MsgBox "Entry Saved"
Else
MsgBox "SaveHeader() Failed"
err.Raise 999, "SaveHeader()", "SaveHeader failed"
End If
Exit Sub
err:
' Rollbacktrans
End Sub
' Returns true if successful
Private Function SaveHeader() As Boolean
On Error GoTo err
'insert statement and other codes
' Function successful, set to true and exit
SaveHeader = True
Exit Function
err:
' Function failed, set to false and exit
SaveHeader = False
End Function
Ya beat me to it erickwidya, but might as well post this anyway
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
January 27th, 2005, 05:07 AM
#9
Re: Procedure Executes after Unload Me Statement
Thx Guys for Immediate Response.
I will Check it out and Reply.
-
January 27th, 2005, 08:02 PM
#10
Re: Procedure Executes after Unload Me Statement
Well, it looks to me like the initial question was a theoretical one, which received a number of practical reponses.
The theoretical answer is:
Private Sub Command1_Click() was popped onto the stack.
Stack = Private Sub Command1_Click()
MsgBox is then executed.
Stack = (from top) Private Sub Command1_Click() , MsgBox.
OK or cancel on MsgBox pops it from stack.
Stack is now = Private Sub Command1_Click()
Unload Me executes
Stack is now = Private Sub Command1_Click() , Unload Me
Unload Me finishes executing
Stack is now = Private Sub Command1_Click()
TestFun executes
Stack is now = Private Sub Command1_Click() , TestFun
TestFun finishes executing
Stack is now = Private Sub Command1_Click()
Private Sub Command1_Click() finishes executing
Stack is now empty.
D
'shut up and play yer guitar' - Frank Zappa
-
January 27th, 2005, 08:54 PM
#11
Re: Procedure Executes after Unload Me Statement
Ya beat me to it erickwidya, but might as well post this anyway
-
February 11th, 2005, 12:19 AM
#12
Re: Procedure Executes after Unload Me Statement
Hi,
Changing the Procedures to Functions is good Solution. But I have more than 100 forms in my project, so i need to change these in all those forms which is tedious and time consuming. Is there any other solution other than this (something like using some API) and unloading form and after unloading it should wait in the MDI Form. The application should not Close.
Help me.
Thx in Advance.
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
|