Home > Archive > Visual Basic > February 2005 > Function to read pass disconnected recordset
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Function to read pass disconnected recordset
|
|
|
| Hi,
My apologies for asking newbie stuff. I'm trying to create a function
to accept a SQL statement as a string, then return back a disconnected
recordset. Could someone help provide a sample? I'm sure that most
people would only take 5 minutes.
What I've achieved so far. Its giving errors.
Public Function fnReadRS(strSQL As String) As ADODB.Recordset
Dim strConn As String
strConn = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=" &
App.Path & "\main.mdb;Uid=Admin;Pwd=;"
'-- connection and recordset
Dim oConn As ADODB.Connection
Dim oRs As ADODB.Recordset
Set oConn = New ADODB.Connection
Set oRs = New ADODB.Recordset
oConn.Open strConn
'-- end
oRs.Open strSQL, oConn, 3, 1
oRs.ActiveConnection = Nothing
Set fnReadRS = oRs
'-- close & destroy
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
'-- end
End Function
| |
| Michael Cole 2005-02-28, 3:55 am |
| naz wrote:
> Hi,
>
> My apologies for asking newbie stuff. I'm trying to create a function
> to accept a SQL statement as a string, then return back a disconnected
> recordset. Could someone help provide a sample? I'm sure that most
> people would only take 5 minutes.
>
> What I've achieved so far. Its giving errors.
What errors is it giving?
--
Regards,
Michael Cole
| |
|
| "Operation is not allowed when the object is open"
when I set ActiveConnection to Nothing
| |
| Michael Cole 2005-02-28, 3:55 am |
| naz wrote:
> "Operation is not allowed when the object is open"
> when I set ActiveConnection to Nothing
May be inconsiquential, but try putting a SET in front of it: - ie,
> Set oRs.ActiveConnection = Nothing
--
Regards,
Michael Cole
| |
| Prasad Athrayil 2005-02-28, 8:55 am |
| Now the function will work fine.
Public Function fnReadRS(strSQL As String) As ADODB.Recordset
Dim strConn As String
strConn = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=" &
App.Path & "\main.mdb;Uid=Admin;Pwd=;"
'-- connection and recordset
Dim oConn As ADODB.Connection
Dim oRs As ADODB.Recordset
Set oConn = New ADODB.Connection
Set oRs = New ADODB.Recordset
oConn.Open strConn
'-- end
oRs.Open strSQL, oConn, 3, 1
'''oRs.ActiveConnection = Nothing
Set fnReadRS = oRs
'-- close & destroy
'''oRs.Close
'''oConn.Close
'''Set oRs = Nothing
'''Set oConn = Nothing
'-- end
End Function
"naz" <nazrix@gmail.com> wrote in message
news:1109572867.314406.319750@z14g2000cwz.googlegroups.com...
> "Operation is not allowed when the object is open"
> when I set ActiveConnection to Nothing
>
| |
|
| I managed to get it working. Below is the code in case others want to
use:
****************************************
*************
Public Function fnReadDB(strSQL As String) As ADODB.Recordset
Dim strConn As String
strConn = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq=" &
App.Path & "\main.mdb;Uid=Admin;Pwd=;"
'-- connection and recordset
Dim oConn As ADODB.Connection
Dim oRs As ADODB.Recordset
Set oConn = New ADODB.Connection
Set oRs = New ADODB.Recordset
oConn.Open strConn
'-- end
oRs.CursorType = adOpenStatic
oRs.CursorLocation = adUseClient
oRs.Open strSQL, oConn, 0, 1
Set fnReadDB = oRs
oRs.ActiveConnection = Nothing
'-- close & destroy connection
oConn.Close
Set oConn = Nothing
'-- end
End Function
****************************************
*************
|
|
|
|
|