|
-
Jul 18th, 2005, 01:13 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Force END
when i close my program it keeps running in the background as a process what can i put under the form unload even to close eveything that the program does
Last edited by WilliamRobinson; Jul 19th, 2005 at 06:02 AM.
Nothing is Impossible you say?......Try slamming a revolving door!
-
Jul 18th, 2005, 01:16 PM
#2
PowerPoster
Re: Force END
On Error Resume Next
'/////////////////////////////
'clear out all open forms
'/////////////////////////////
Dim MyForm As Form
For Each MyForm In Forms
Unload MyForm
Set MyForm = Nothing
Next MyForm
End
-
Jul 18th, 2005, 01:19 PM
#3
Re: Force END
Put END as the last statement in your form_unload to kill everything. But better than this is to spend some time and find out why your program is not terminating. May be some infinite loop or someting may be the cause.
Pradeep
-
Jul 18th, 2005, 01:21 PM
#4
Thread Starter
Addicted Member
Re: Force END
Thanks a mill
worked fine
Nothing is Impossible you say?......Try slamming a revolving door!
-
Jul 18th, 2005, 01:25 PM
#5
Re: Force END
That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim frm As Form
Dim obj As Object
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
For Each obj In frm
On Error Resume Next
Unload obj
Set obj = Nothing
Next
Unload frm
Set frm = Nothing
End If
Next
On Error Resume Next
For Each obj In frm
Unload obj
Set obj = Nothing
Next
Set frm = Nothing
Unload Me
End Sub
-
Jul 18th, 2005, 01:29 PM
#6
Re: Force END
 Originally Posted by dglienna
That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.
It will fail here and this is exactly the situation I was talking about in my post #3 (infinite loops)
VB Code:
Private Sub Form_Load()
Me.Show
Do
DoEvents
Loop
End Sub
Pradeep
-
Jul 18th, 2005, 08:44 PM
#7
Re: Force END
 Originally Posted by dglienna
That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim frm As Form
Dim obj As Object
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
For Each obj In frm
On Error Resume Next
Unload obj
Set obj = Nothing
Next
Unload frm
Set frm = Nothing
End If
Next
On Error Resume Next
For Each obj In frm
Unload obj
Set obj = Nothing
Next
Set frm = Nothing
Unload Me
End Sub
Don't you only need to call On Error Resume Next once, like as the first line of this sub?
-
Jul 18th, 2005, 10:41 PM
#8
Re: Force END
Never had a problem with it, and it only gets called once. I really don't think the first object would be an error. Only when an object doesn't exist.
Not sure, but I think it's for the FOR EACH object IN Forms only.
-
Jul 19th, 2005, 05:23 AM
#9
Re: Force END
On Error Resume Next resumes to the next line of code after the sub, which means it's pretty much an Exit Sub/Function only when an error has occured. Which is why it only needs to be called once. I rewritten your code to use modularly:
VB Code:
Public Sub Close_Program(Main_Window As Form)
On Error Resume Next
Dim Frm As Form
Dim Obj As Object
For Each Frm In Forms
If Frm.Name <> Main_Window.Name Then ' Unload this form LAST
For Each Obj In Frm
Unload Obj
Set Obj = Nothing
Next Obj
Unload Frm
Set Frm = Nothing
End If
Next Frm
For Each Obj In Frm
Unload Obj
Set Obj = Nothing
Next Obj
Set Frm = Nothing
Unload Main_Window
End
End Sub
-
Jul 19th, 2005, 06:01 AM
#10
Thread Starter
Addicted Member
Re: Force END
Ok thanks every1 for your time this is now resolved
Nothing is Impossible you say?......Try slamming a revolving door!
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
|