Solved

Returning Recordset from a Active X DLL

Posted on 2001-06-09
6
197 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Contents of a Directory In Access VBA 5 70
MsgBox 2 57
Determine Range to Select 5 48
How to LOAD up a .NET Framework website with data? 2 56
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

821 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