Kayleigh
Member
- Local time
- Today, 03:26
- Joined
- Sep 24, 2020
- Messages
- 706
Hi
I'm wondering if anyone has code that can close open objects in particular emails. I think these are still knocking about in my database and causing issues.
I have code to close all recordsets when DB closes so looking for something to that effect.
Like this:
I'm wondering if anyone has code that can close open objects in particular emails. I think these are still knocking about in my database and causing issues.
I have code to close all recordsets when DB closes so looking for something to that effect.
Like this:
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 <> "frmLogin" Then
' DoCmd.Close acForm, frm.Name
' 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