Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to release memory on Acces/close all open recordsets

VB for apps

How to release memory on Acces/close all open recordsets

by  patyavila  Posted    (Edited  )
It's important to close all recordsets when exiting to release memory. I found this code I've been using since then with good results. Put this on a global module so you'll have it available every time you need, specially on exit or close button of the Main Menu. Make sure you have no bound forms open.

Code:
Public Function CloseAllRecordsets() As Integer
Dim wsCurr As Workspace
Dim dbCurr As Database
Dim dbWrite As Database
Set dbWrite = CurrentDb
Dim Str As String
Dim Rs As Recordset
Dim frm As Form
For Each frm In Application.Forms
  If frm.Name <> "UserLogin" Then
    frm.Close
  End If
Next
For Each wsCurr In Workspaces
    For Each dbCurr In wsCurr.Databases
        For Each Rs In dbCurr.Recordsets
            Str = "INSERT INTO [OpenRecordSets] ( [RSname], [RsCount], [Date] ) SELECT '" & Rs.Name & "'," & Rs.RecordCount & ",#" & Date & "#"
            dbWrite.Execute Str
            MsgBox "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

:-D


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top