Solved

Returning Recordset from a Active X DLL

Posted on 2001-06-09
6
201 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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