will END close all my recordsets and connections

In VB6 will the command END close all my recordsets and connections?  Or is it necessary to close all of them manually first.  I figure whats the big deal if I close my whole application by the command END.  Are there things still resident in memory afterwards?
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
You should never use End. When you do VB doesn't get a chance to clean up after itself and a lot of things may be left in memory including a "shadow" of your running app.

What version of VB or VBA are you using?
0
al4629740Author Commented:
VB6..
0
Martin LissOlder than dirtCommented:
Then add a routine like this which will (as you can surly tell) will unload all your forms.
Public Sub UnloadAllForms()

    Dim frm As Form
    
    On Error GoTo ErrorRoutine
    
    For Each frm In Forms
        Unload frm
        Set frm = Nothing
    Next
    
    Exit Sub

ErrorRoutine:

    Msgbox "UnloadAllForms " & Err.Description
    
End Sub

Open in new window


and call it from your main form's QueryUnload event and/or any "Exit" type menu item you might have.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

al4629740Author Commented:
This will close all record sets properly and connections?
0
Martin LissOlder than dirtCommented:
Unless they are global in scope then I believe it will and if they are global you should disconnect from them in that procedure.
0
HooKooDooKuCommented:
Everything depends upon the scope of the record sets.

If the record sets are defined at the form level, then you could add to each form's Unload or Terminate event the logic to close the record set if it is open, and then set the record set to nothing.  Then something like Martin's idea to explicitly unload each form might work.  But even then, you might have to deal with some parent /child relationships depending upon  the complexity of your project.

Private m_rs As DAO.Recordset
Private Sub Form_Terminate()
    Call CloseRS
End Sub
Private Sub CloseRS()
    If Not m_rs Is Nothing Then
        Call m_rs.Close
        Set m_rs = Nothing
    End If
End Sub

Open in new window


But the way I liked to work was start every VB application with a Global.bas file.  I would declare my global forms and global objects in this file and always start in Sub Main().  I would then load the global objects and forms  and other program initialization  in Sub Main.  I would also create a subroutine in Global.bas called MainEnd().  The purpose of this subroutine was to unload the global forms and global objects.  Like the example above, I would simply look to see if a given object was not set to nothing.  That would indicate that at some point, the application had loaded the global object, so in MainEnd I would close it and set it back to Nothing.  That way, I could terminate my application at any point by calling MainEnd.  That would unload and terminate global objects and forms, and the Unload and Terminate events of these global objects would unload and terminate their child objects.
0
al4629740Author Commented:
I do have global variables.  Is there a simple routine that can set that all to nothing?
0
Martin LissOlder than dirtCommented:
If they are in a form, setting the form to Nothing will get rid of them. Otherwise you can create a procedure like this one and call it.

Public Sub SetToNothing()

Set x = Nothing
Set y = Nothing
'etc.
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
al4629740Author Commented:
as hookoodooku indicated, do I need to close the recordsets?
0
Martin LissOlder than dirtCommented:
As long as you don't use End you can probably get away with not explicitly closing them, but it's good programming practice yo close them when you are done with them.
0
al4629740Author Commented:
What is the purpose of END anyways?
0
Martin LissOlder than dirtCommented:
It's hard to say. Maybe they wanted the programmer to have a way out of the code if he really, really doesn't care about the consequences of abruptly stopping VB.
0
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.