Solved

Returning Recordset from a Active X DLL

Posted on 2001-06-09
6
192 Views
Last Modified: 2013-11-25
Is it possible to return a recordste from a DLL wriiten in VB. If so then how and if not then is there any other alternative.
Best Regards.
Shehzad Munir.
0
Comment
Question by:ShehzadMunir
  • 4
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6172753
Yes, you need a property/function who's return value is type Recordset (ADO or DAO)

example:
' Needs a reference to ADO objects in your dll
Property get RetRecordset() as ADO.recordset
set RetRecordset= yourchoice  ' valid recordset


' Needs a reference to DAO objects in your dll
Property get RetRecordset() as DAO.recordset
set RetRecordset= yourchoice  ' valid recordset

You could create those recordsets in or out your property procedure.

Do you need more specific code?
Let me know.
Cheers
0
 

Author Comment

by:ShehzadMunir
ID: 6172850
Yes I would like to have more specific code segment.
Best Reagrds
Shehzad Munir
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6176397
Public Function GetDisconnectedRS(SQL As String, Provider As String) As ADODB.Recordset
           
        Dim adoConnection   As ADODB.Connection
       
       
        ' Set up the recordset
        Set GetDisconnectedRS = New ADODB.Recordset
        GetDisconnectedRS.CursorLocation = adUseClient
       
        ' Open a connection to the DB
        ' Doing this after we set up the recordset ensures that
        ' we hold on to the connection for the least
        ' possible amount of time, and release it as soon
        ' as we have opened the recordset.
        Set adoConnection = New ADODB.Connection
        adoConnection.CursorLocation = adUseClient
        adoConnection.Open Provider
           
        ' Open the Recordset with this connection
        GetDisconnectedRS.Open SQL, adoConnection, adOpenForwardOnly, adLockReadOnly
       
        ' Disconnect recordset & close connection
        Set GetDisconnectedRS.ActiveConnection = Nothing
        adoConnection.Close
        Set adoConnection = Nothing
                       
End Function
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6177388
'Set a reference to Microsoft Active x data objects 2.5
'Set a reference to Microsoft DAO 3.6 objects

This function should returns either a DAO recorset or an ADO recordset depending on what you are passing as arguments.

NOTE: I think it is not fully funciolan but it has enougth info to get the idea.

NOTE2: Since one of the recordset is always opened, when you finish working with it, close the db or connection and set references to nothing with some function by your own.
I left a parameter (ByRef TypeSelected As rsTYPE) where the function stores which type of recordset is returning. You could use it to clear objects variables.
If you need more, don't be affraid and ask...
cheers
Option Explicit
    Private db As DAO.Database
    Private rsDAO As DAO.Recordset

    Private conn As ADODB.Connection
    Private rsADO As ADODB.Recordset

Public Enum rsTYPE
    rsDAO = 0
    rsADO = 1
End Enum
Public Function RecSet(ByVal recsetType As rsTYPE, ByVal sSQL As String, ByVal sDBPath_Name As String, ByRef TypeSelected As rsTYPE, Optional sProvider As String) As Object
Select Case recsetType
Case 0  'DAO
    Set db = DBEngine.Workspaces(0).OpenDatabase(sDBPath_Name, False, False, True)
    Set rsDAO = db.OpenRecordset(sSQL, dbOpenDynaset)
    Set RecSet = rsDAO
   
   
Case 1  'ADO
    With conn
        .ConnectionString = sProvider & sDBPath_Name
        .Open
    End With
    If conn.State = adStateOpen Then
        Set RecSet = rsADO.Open(sSQL, conn, adOpenDynamic, adLockOptimistic)
    End If
End Select
End Function


0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 10 total points
ID: 6177416
ups!
Public Enum rsTYPE
   rstDAO = 0
   rstADO = 1
End Enum
Public Function RecSet(ByVal recsetType As rsTYPE, ByVal sSQL As String, ByVal sDBPath_Name As String,
ByRef TypeSelected As rsTYPE, Optional sProvider As String) As Object
Select Case recsetType
Case 0  'DAO
   Set db = DBEngine.Workspaces(0).OpenDatabase(sDBPath_Name, False, False, True)
   Set rsDAO = db.OpenRecordset(sSQL, dbOpenDynaset)
   Set RecSet = rsDAO
   TypeSelected=0
   
Case 1  'ADO
   With conn
       .ConnectionString = sProvider & sDBPath_Name
       .Open
   End With
   If conn.State = adStateOpen Then
       Set RecSet = rsADO.Open(sSQL, conn, adOpenDynamic, adLockOptimistic)
       TypeSelected=1
   End If
End Select
End Function

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6199140
Hi, thanks for B grade.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now