Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return ADO Recordset from Function
Message
From
19/12/2001 15:04:47
 
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00596301
Message ID:
00596388
Views:
16
>I have a funcion in class module that returns an ADODB.Recordset. I understand the theory behind this. My problem is that I do not know how to return the recordset to the calling sub. Here is the inf:
>
>Public Function GetRS(SQL As String) As ADODB.Recordset
> 'SET THE CONNECTION STRING PROPERTY TO A VALID CONNECTION STRING
> 'PASS AN SQL STATEMENT TO THIS FUNCTION
> 'THE RETURN VALUE WILL BE AN ADODB RECORDSET
>
> Dim rs As New ADODB.Recordset
> On Error GoTo LocalError
> With rs
> .ActiveConnection = ConnectionString
> .CursorLocation = adUseClient
> .LockType = adLockOptimistic
> .CursorType = adOpenKeyset
> .Source = SQL
> .Open
> Set .ActiveConnection = Nothing
> End With
> Set GetRS = rs
> Set rs = Nothing
>Exit Function
>LocalError:
> m_sLastError = Err.Number & " - " & Err.Description
> Set rs = Nothing
>End Function
>
>What do I need to do in the calling function to return the recordset? I tried to declare a recordset and do something like:
>
>rst = GetRS(strSQL)
>
>This is not work. Said invalid use of property or something.
>Anyone have some help?

This call should work:
Dim oRS As ADODB.Recordset
Set oRS = getRS(myCnString)
HTH
Previous
Reply
Map
View

Click here to load this message in the networking platform