troubleshooting Question

Excel2003-VBA-ADODB How do I store a recordset in memory?

Avatar of Grizzler
GrizzlerFlag for United States of America asked on
Microsoft Excel
10 Comments1 Solution817 ViewsLast Modified:
I want to read data into a recordset, close the connection to source, and use the snapshot from memory. The data never gets written back, it is read only and not particulary dynamic.

I would like to stay with the recordset type as my current code is built around it and I use the recordset.filter to retrieve data for populating cells.

here's my code

    Dim Rst As ADODB.Recordset
    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection

    With cn
        .Provider = "MSDASQL"
        .ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DBQ= myfile.xls; ReadOnly=False;"
        .Open
    End With


    Dim strQuery As String
    strQuery = "SELECT * FROM DATA WHERE [FTN] > 0"
    Set Rst = cn.Execute(strQuery)

 '* DO STUFF
   
    cn.Close
'* RST becomes unavailable when cn is closed

    Set cn = Nothing
    Set Rst = Nothing

I want to clone the recordset and keep it in memory after closing cn.... How do I accomplish this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros