Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default ADODB Recordset Function

Jim,

Don't close the RS, just set the connection to nothing to get a disconnected
recordset. Stephen Bullen's VBA book is quite a good ref on this. You might
also want to have a look at http://www.able-consulting.com/ADO_Faq.htm

This is an extract of the kind of thing you need:

Public Function DsRs(strSQL as String) as ADODB.Recordset
'set up the connnection string here
Set DsRs = New ADODB.Recordset
With DsRs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
End With
DsRs.Open strSQL, strCon, , , adCmdText
Set DsRs.ActiveConnection = Nothing
Exit Function

Robin Hammond
www.enhanceddatasystems.com

"Jim Thomlinson" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default ADODB Recordset Function

Thanks a bunch...

"Robin Hammond" wrote:

Jim,

Don't close the RS, just set the connection to nothing to get a disconnected
recordset. Stephen Bullen's VBA book is quite a good ref on this. You might
also want to have a look at http://www.able-consulting.com/ADO_Faq.htm

This is an extract of the kind of thing you need:

Public Function DsRs(strSQL as String) as ADODB.Recordset
'set up the connnection string here
Set DsRs = New ADODB.Recordset
With DsRs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
End With
DsRs.Open strSQL, strCon, , , adCmdText
Set DsRs.ActiveConnection = Nothing
Exit Function

Robin Hammond
www.enhanceddatasystems.com

"Jim Thomlinson" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 97 ADODB Recordset.Find "Invalid Use" error Robin Hammond[_2_] Excel Programming 1 August 27th 04 12:47 PM
ADODB Recordset problem Stefen Percoco Excel Programming 2 July 26th 04 06:31 PM
0 with ADODB Recordset Stefen Percoco Excel Programming 1 July 8th 04 09:54 PM
adodb.recordset with excel nate axtell Excel Programming 14 June 11th 04 01:32 PM
ADODB Recordset Seth[_3_] Excel Programming 0 August 5th 03 02:15 PM


All times are GMT +1. The time now is 06:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"