Passing a Recordset and Closing It

Am I right in assuming that if I have a method that connects to a database, reads records into a recordset and then passes that recordset to a calling process, the recordset that is in the method is automatically closed as on return the method loses scope? This is what I am reading in the docs but not 100% sure.

So then the only recordset I actually need to close is the one I setup to receive the recordset?

For example

GetData is the method that created the recordset

Dim rs As Recordset = GetData


Should I also add


To be safe?

A RecordSet is closed when all references to it go out of scope.

If GetData creates a RecordSet and returns it:

Dim rs As RecordSet = GetData

Then the only remaining reference to the RecordSet is “rs”. The RecordSet will close when “rs” goes out of scope or if you close the RecordSet manually with rs.Close.

Thanks Paul, so it was as I expected, so that means I do not need to use GetData.Close then, as it was automatically closed once the GetData method returned the recordset and lost scope.