Solved

Returning Recordset from a Active X DLL

Posted on 2001-06-09
6
189 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now