View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default ADODB Recordset Function

I have a function that is supposed to return an ADODB.RecordSet. The code is
shown below. My problem is that when I close the connection and close the
recordset in this function the function returns nothing. I commented out the
lines and it works fine. How doe I Keep the recordset even after the
connection has been closed?


Public Function RunQuery(ByVal strSelect As String, ByVal strFrom As String, _
ByVal strWhere As String, ByVal strOrderBy) As ADODB.Recordset

Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset

'Open connection to the database
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
m_cDBLocation & ";"
rst.Open m_cUpdateDetailsFile, cnt, adOpenKeyset, adLockOptimistic,
adCmdTableDirect

Set rst = cnt.Execute(strSelect & " " & strFrom & " " & strWhere & " " &
strOrderBy)

Set RunQuery = rst

' ' Close ADO objects
' rst.Close
' cnt.Close
' Set rst = Nothing
' Set cnt = Nothing