devxlogo

Reuse a Recordset’s Connection

ADO lets you create a Recordset without creating an explicit Connection object, using the following syntax:

Dim rs As New ADODB.Recordsetrs.Open "Authors", "DSN=Pubs"

If you later want to create another Recordset, but you (correctly) don’t want to create another database connection, you can reuse the implicit Connection object that ADO has created for the first Recordset, as in:

Dim rs2 As New ADODB.RecordsetSet rs2.ActiveConnection = rs.ActiveConnectionrs2.Open "Publishers"

or, more simply, with

Dim rs2 As New ADODB.Recordsetrs2.Open "Publishers", rs.ActiveConnection

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.