If I declare a db as the current database, do I have to close it or does it matter if I close it or just leave it alone? I have a recordset and when I'm done with the record set I close it and set it to nothing, and I'm wondering if I have to do the same for the database.
Dim dbs As DAO.Database
Dim rdset As DAO.Recordset
Dim sqlStr As String
sqlStr = " select * from contact"
Set dbs = CurrentDb()
Set rdset = dbs.OpenRecordset(sqlStr)
If rdset.EOF Then
Set rdset = Nothing
I never close my database after I have run it in VBA. I think when the code reach to the 'END SUB', it would close the connection to the database. I have never had problem with it, on not closing it though.
It is good practice to close the database object. It can cause problems in some conditions, though not often in normal practice. It is good practice to close all open objects when they are no longer needed, "just in case"
Another point is that set object = nothing and object.close are in effect different methods of doing the same thing, so only one or the other is necessary, whichever you prefer.