|
vb123.com
Garry Robinson's Popular MS Access, Office and VB
Resource Site
 |
|
Home
Contact Us
Order our Software
RSS &
Newsletter
Join our XML/RSS Newsfeed or sign up for our informative newsletter on
Office Automation, Access and VB topics
Read More
Get Good Help
If you need help with a database, our Professionals could be the answer
Read More
Is Your Database Corrupt ?
If you have a corrupt database,
Try our Access Recovery
service
The
Workbench
Find out who has your database open, start the
correct version of Access, easy compacting and backups, change startup
options, mde compile, shutdown database
Read and
Download
The Toolshed
Searchable help file comprising of all the information at vb123.com plus
hidden downloads etc. Read More
The Toolbox
Libraries of software that we regularly import into our projects. This
is a newer version of the Toolshed
More..
Access >>> SQL
Upsize to SQL Server 2005 or 2008, easily repeated conversions,
highly accurate SQL query
translation and web form conversion.
Read More
SharePoint
For our company file sharing and task management, we use
SharePointHosting
DryToast
Backup and query your BaseCamp®
projects
Read More
Datamining/Graphs
Explore your data with this versatile graphing and data mining shareware
tool. Read 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 ...
Search ...
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
|