PDA

Click to See Complete Forum and Search --> : Return a recorset with a function


FrancisC
Mar 29th, 2000, 12:58 AM
I am trying to write a function that will return a recordset:

Property Get QueryResult() As Recordset

Dim ado as New Recordset

'Other declarations and execution of the query here

QueryResult = ado

End Property


The line 'QueryResult = ado' gives me an error: 'Inalid use of Property'. Can someone tell me how I can pass this recordset as a variable ?

Thanks

Jaguar
Mar 29th, 2000, 03:14 AM
You need to use the set command. This is because the function is supposed to return an object, therefore you need to use "Set QueryResult = ado"

I have used this exact principle in my program, here is the code.

Public Function RecordsetEx(ByVal Source As String, _
conn As Object, _
Optional ByVal CursorType As CursorTypeEnum = adOpenUnspecified, _
Optional ByVal LockType As LockTypeEnum = adLockUnspecified, _
Optional ByVal Options As Long = -1) As Object
If conn Is Nothing Then
MsgBox "Nothing can be done because an active _
connection object has not been supplied.", vbInformation
Exit Function
End If
Set RecordsetEx = New ADODB.Recordset
RecordsetEx.Open Source, conn, CursorType, LockType, Options
End Function,