Whats the difference between rs.close vs rs = nothing in a RecordSet Whats the difference between rs.close vs rs = nothing in a RecordSet vba vba

Whats the difference between rs.close vs rs = nothing in a RecordSet


By using the "Close" method you are closing the connection to the database but is still in the memory where you can open again using the "Open" method.

Setting the recordset to "Nothing" on the other hand releases the object completely from the memory.


The Close method tears down the memory structure.

Setting the variable to Nothing clears the pointer to that memory structure.

Theoretically, clearing the pointer should release the memory the pointer was referring to, because VBA uses reference counting for determining when it can release memory. Unfortunately, various things can go wrong and the reference count can end up out of whack, and memory won't be released even when it should be.

Thus, to be sure you're not subject to memory leaks, or the weird kinds of bugs caused by implicit and unreleased references, you both Close and set to Nothing.


You can set Recordset to Nothing without needing to call Close, according to official documentation:

An alternative to the Close method is to set the value of an object variable to Nothing (Set dbsTemp = Nothing).

More info: Recordset.Close Method (DAO)