Results 1 to 2 of 2

Thread: Return a recorset with a function

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Posts
    161
    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

  2. #2

    Use the SET command

    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.

    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,
    Senior Systems Architect/Programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width