[AccessD] Recordset collection

John Colby jwcolby at gmail.com
Fri Aug 20 13:10:15 CDT 2021


You can pass pointers to recordsets as parameters in functions.  You can
store pointers to said recordsets in a variable
function fExample(lRst as dao.recordset)
dim rst as dao.recordset
   set rst = lrst
end function

These recordset variables can be in the header of a module.

dim mRst as dao.recordset

function fExample(lRst as dao.recordset)
   set mRst = lrst
end function

I create them in class headers and in the class_Terminate I close them

Private Sub Class_Terminate()
    On Error Resume Next
    mRst.Update
    mRst.Close
    Set mRst = Nothing
    Set mDb = Nothing
End Sub

Lots of ways to keep a pointer to a recordset around as well as clean them
up afterwards.



On Fri, Aug 20, 2021 at 9:50 AM Jim Dettman via AccessD <
accessd at databaseadvisors.com> wrote:

> Arthur,
>
>  << it lives on, and a subsequent open recordset "name" opens it with its
> previous contents intact. Is this correct>>
>
>  You may be thinking of another product, as Access doesn't work that way.
> Access/VBA does internally track open references like recordset objects,
> but
> it's nothing you can get at.
>
>  Normally, a recordset is closed and the object variable is destroyed when
> the object variable goes out of scope, although some say the Close might
> does not get done if you don't explicitly do it.
>
>  So it's best to always do:
>
>  On Error Resume Next
>
>   If not rst is nothing then
>         rst.close
>         Set rst = nothing
>  End if
>
>  At the end of a procedure to make sure it gets done correctly.
>
>  If you don't do this, sometimes Access can hang when closing if something
> is still open.   One way to avoid that problem entirely is to use the Priv
> DB Engine object.   With that, you can in code create a new instance of the
> JET Engine.   Anything you do through instance won't be tracked by Access,
> so if something is left hanging open, it won't stop Access from closing
> (Access only looks at its own JET Engine session).
>
>  Note that you may see a re-open of a previous record set occur more
> quickly
> if the pages needed are sitting in the page cache, but you are always
> opening a new memory object and filling it.
>
> HTH,
> Jim.
>
>
> -----Original Message-----
> From: AccessD On Behalf Of Arthur Fuller
> Sent: Friday, August 20, 2021 8:24 AM
> To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>
> Subject: [AccessD] Recordset collection
>
> As I understand it; recordsets when created  are placed in a collection.
> Unless an rs is closed (rs.close), it lives on, and a subsequent open
> recordset "name" opens it with its previous contents intact. Is this
> correct
>
> What is this collection called? What does it store exactly?
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list