[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Returning Recordset from a Active X DLL

Posted on 2001-06-09
6
Medium Priority
?
222 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 30 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

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

834 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