×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Microsoft: Office FAQ

VB for apps

How to release memory on Acces/close all open recordsets by patyavila
Posted: 20 Jan 06

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

big smile



Back to Microsoft: Office FAQ Index
Back to Microsoft: Office Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close