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 :wave:
Printable View
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 :wave:
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
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 :)
Thanks a mill
worked fine
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
It will fail here and this is exactly the situation I was talking about in my post #3 (infinite loops)Quote:
Originally Posted by dglienna
VB Code:
Private Sub Form_Load() Me.Show Do DoEvents Loop End Sub
Pradeep :)
Don't you only need to call On Error Resume Next once, like as the first line of this sub?Quote:
Originally Posted by dglienna
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.
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
Ok thanks every1 for your time this is now resolved