psemianonymous
Programmer
I think this is a widely-propogated fallacy--when you use your local Database object, you do not have to use the ".Close" method when you're done with it. An example:
Note that you should close Recordsets that you open. And note that you should close Databases that you opened, like in the following:
Code:
Sub UseLocalDB()
On Error GoTo Sub_Error
Dim db As DAO.Database
Dim rs As DAO.Recordset
Code:
'Note we did not open the database
Code:
Set db = CurrentDb()
'could also use:
'Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("qrySomeQuery")
Sub_Exit:
On Error Resume Next
rs.Close
Set rs = Nothing
Code:
'db.Close *NOT NECESSARY*
Code:
Set db = Nothing
Exit Sub
Sub_Error:
MsgBox Err.Description
Resume Sub_Exit
End Sub
Note that you should close Recordsets that you open. And note that you should close Databases that you opened, like in the following:
Code:
Sub UseSomeOtherDB()
On Error GoTo Sub_Error
Dim db As DAO.Database
Dim rs As DAO.Recordset
Code:
'Note we opened the database
Code:
Set db = DBEngine(0).OpenDatabase("C:\somedir\SomeFile.MDB")
'could also use:
'Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("qrySomeQuery")
Sub_Exit:
On Error Resume Next
rs.Close
Set rs = Nothing
Code:
'db.Close should be used here
Code:
db.Close
Set db = Nothing
Exit Sub
Sub_Error:
MsgBox Err.Description
Resume Sub_Exit
End Sub