Results 1 to 3 of 3

Thread: Returning Recordsets from DLL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Atlanta, GA
    Posts
    80

    Question

    Can I return a Recordset from a DLL called by my EXE?

    My DLL does all DB access and I would like to return an actual recordset in some cases to easily populate a grid with the RS information.

    I get an error when I do as follows:

    *****************************************************
    Command_Click
    *****************************************************
    Dim objCase As LBCom2.Case
    Set objCase = CreateObject("LBCom2.Case")

    Dim objRS As ADODB.Recordset
    Set objRS = CreateObject("ADODB.Recordset")

    objRS.ActiveConnection = Nothing

    Set objRS = objCase.GetCases

    Do While Not objRS.EOF
    ..... Grid Code Here
    Loop
    *****************************************************
    The GetCases Function Returns a Recordset, but I get and error trying to access the RS within the EXE.

    Error 3704-Operation not allowed when the object is closed.

    I don't have a connection to open it with....

    What can I do???

    Thanks!
    Kevin
    Kevin

  2. #2
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    Not sure if you can pass a recordset from a dll (I'm not sure if VB allows it, if it doesn't you can just return it as Object). But you don't need to do a createobject first, this is enough:
    Dim rs As ADODB.Recordset
    Set rs = Class.Function

    With createobject you create a new instance of the recordset; which you don't want, you want to have a reference to the recordset created in the class.
    But I believe M$ says that it's not smart to pass object around from a dll to an exe, so f it fails, you can also let the function return the SQL Query, and open the recordset in your exe.
    Hope this helps

    Crazy D

  3. #3
    New Member
    Join Date
    Aug 2000
    Posts
    15
    Yes you can! you need to use disconnected recordsets.

    "dim myrs as ADOR.recordset"

    Just make your function return a recordset i.e.

    function Myfunction() as ador.recordset
    dim tempdb as adodb.recordset
    etc
    .
    .

    open connection to database
    set myfunction = tempdb
    end function

    in your EXE just declare a ADOR.recordset
    and the following code
    "Set myrs = myfuction"

    Remember this is a disconnected recordset so won`t see changes made to the database etc.



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