If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Close button does not entirely unload project

I have a project that fails to totally unload the app when the close button is selected ('X' in control box at top of the form). I have to put a button in the form to close the app completely from memory using something like:

Code:

Private Sub exitNow()
Unload Me
End Sub

Why will the app not unload with the 'Close' button on the form itself? What can I do to force it to unload all the way?

Re: Close button does not entirely unload project

How about using ;

Code:

Private Sub exitNow()
END
End Sub

or do you have some code in the Form_Unload Event ?

Originally posted by rick7423
I have a project that fails to totally unload the app when the close button is selected ('X' in control box at top of the form). I have to put a button in the form to close the app completely from memory using something like:

Code:

Private Sub exitNow()
Unload Me
End Sub

Why will the app not unload with the 'Close' button on the form itself? What can I do to force it to unload all the way?

I use the ExitNow method whenever I want the app to unload from somewhere. It is a generic call to unload the app, and yes, I also use the 'END' function in conjunction with 'Unload Me'.

This works fine and the app unloads correctly IF this function is called. What does NOT work is the close button in the control box at the top of the form (the min, max and close buttons). The close ('X') does not entirely unload the app (i.e. it still shows as running in Task Manager).

I have to disable the control box and force the app to use my internal functions and methods to close the app completly. the problem is, I want to enable the min/max/close features of the control box.

First, avoid "END": it is an abrubtly stop , and ususally it is not needed at all.
What you need is:
stop all loops, deactivate all timers, close and set to nothing all referenced objects, unload all forms.

To stop loops (those where you have a doevents inside, else your app is frozen...) :
have a global bStop as Boolean; in query_Unload event of forms where loop is (or of your mainform) code
bStop = true
'There code also any timer.enabled = false

In loops after doevents (or in timers, inside the timper_procedure) code:

Code:

if bStop then
'close any private opened object, like word doc,
'recordsets and so on that belongss to this procedure
'if any
exit sub
end if

In main form query unload, ensure you unload all forms:

Code:

Dim FrmX as Form
For Each FrmX in Forms
If FrmX.hwnd<>Me.hwnd 'no sense to unload this already unloading form
Unload FrmX
end if
Next

Note the code for cleaning you write in query unload will be
called also when user press the "X" button...But if you call "end",
the code in quety unload of any other form will not trig. Nor will
any code in any other object or in your same object after
the "end" line.

Last edited by Cimperiali; July 12th, 2004 at 10:40 AM.

...at present time, using mainly Net 4.0, Vs 2010

Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.