|
vb123.com
Garry Robinson's Popular MS Access, Office and VB
Resource Site
 |
|
Home
Contact Us
Order Software
Search vb123
Smart
Access
The Magazine that Access Developers loved to read and write for is back
Article Index Here or
Purchase Here
RSS &
Newsletter
Join our XML/RSS Newsfeed or sign up for our informative newsletter on
Office Automation, Access and VB topics
Sign up here
Get Good Help
If you need help with a database, our Australian Professionals could be
the answer
Read More
The
Workbench
Find out who has
your database open, start the correct version of Access, easy compacting
and zip backups, change startup options, compile, shutdown
database
Read and
Download
Access > SqlServer
Upsize to SQL Server 2005 or 2008, easily repeated conversions,
highly accurate SQL query
translation and web form conversion.
Read More
Like FMS Products?
Purchase them from us and get a free Workbench or Smart Access
More
The Toolbox
Libraries of software that we regularly import into our projects.
More..
Garry's Blog
Find out a few other things that
Garry has been writing about Microsoft Access.
Read more
About The Editor Garry
Robinson writes for a number of popular computer magazines, is now a
book author and has worked on 100+ Access databases. He is based in
Sydney, Australia
Contact Us ...
or try our new site built with
SharePoint Designer
vb123.com.au
|
| |
Save Memory By Closing Open
Recordsets
If you use any data objects in
your code (DAO, RDO, or ADO), you should be sure to explicitly close all
open recordsets, databases, and workspaces before you exit. Even though
the pointers to these objects are automatically destroyed when you exit
the program, if you fail to explicitly close all open items, your database
connections may not be immediately released and the memory used by these
objects may never be re-allocated by the operating system. Here's a short
routine you can add to your Form_Unload event (or some other terminating
code module) that will close all open DAO workspaces, databases, and
recordsets and release the memory reserved by these objects. This code
will work whether you have 1,
100, or even no connections open when you attempt to exit the form.
'--------------------------------------------------
Public Function CloseAllRecordsets() As Integer
'--------------------------------------------------
on error resume next
'Be sure to Close all Data Objects upon Exit - and release memory
'Put it on close of the Main Menu - (make sure you have no bound forms open)
Dim wsCurr As Workspace
Dim dbCurr As Database
Dim Rs As Recordset
Dim Frm As Form
For Each wsCurr In Workspaces
For Each dbCurr In wsCurr.Databases
For Each Rs In dbCurr.Recordsets
MsgBox "The
recordset " & vbCrLf & Rs.Name & vbCrLf & _
Rs.RecordCount & " record(s) was left open - now closing it.", vbCritical,
"Validation"
Rs.Close
Set Rs = Nothing
Next
dbCurr.Close
Set dbCurr = Nothing
Next
wsCurr.Close
Set wsCurr = Nothing
Next
End Function
Published January, 1999
|