Get Recordset / Vaiiable(s) from DLL to VB

Posted on 2003-03-05
Medium Priority
Last Modified: 2010-04-07
Hi Experts,

Could you please provide me an example for this :

1) How to make a VB DLL to return Recordset to VB (is it possible)?

2) How to make a VB DLL to return Variable(s) to VB?

3) How to code in the VB to receive the return from (1) ,   (2)?

Thanks a lot
Question by:kchoed

Expert Comment

ID: 8078290

In Class module of DLL for example:

'Set This variables in e.g. Class_Initialize
dim strClassVariable as string

dim rsClassRecordset as string

Public Property Get ReturningVariable() As String
    ReturningVariable = strClassVariable
End Property

Public Function ReturnsRecordset() As ADODB.Recordset
   set ReturningRecordset = rsClassRecordset
end function

In your EXE:

Set obj = new NameOfYourClass

strFromDLL = obj.ReturningVariable

set rsFromDLL = obj.ReturnsRecordset()

LVL 43

Accepted Solution

TimCottee earned 800 total points
ID: 8078607
Indeed Smallint is close,

Your class might look something like this:

Private cnnInformation As ADODB.Connection
Private rstInformation As ADODB.Recordset
Private strInformation As String

Private Sub Class_Initialize()
  'Set default values and initialise connection object
  strInformation = "Hello there"
  Set cnnInformation = New ADODB.Connection
  cnnInformation.ConnectionString = "Your connection string here"
End Sub

Private Sub Class_Terminate()
  'Properly tidy up and release our recordset and connection objects
  If Not (rstInformation Is Nothing) Then
    If rstInformation.State <> adStateClosed Then
    End If
    Set rstInformation = Nothing
  End If
  If Not (cnnInformation Is Nothing) Then
    If cnnInformation.State <> adStateClosed Then
    End If
    Set cnnInformation = Nothing
  End If
End Sub
Public Property Let StringInfo(ByVal NewValue As String)
  strInformation = NewValue
End Property

Public Property Get StringInfo() As String
  StringInfo = strInformation
End Property

Public Property Get RecordsetInfo() As ADODB.Recordset
  Set rstInformation = New ADODB.Recordset
  rstInformation.Open "Select Statement Here",cnnInformation,adOpenStatic,adLockOptimistic
  Set RecordsetInfor = rstInformation
End Property

You can then use in your form:

Private Sub Command1_Click()
  Dim MyClass As DLLProject.Class1
  Set MyClass = New DLLProject.Class1
  With MyClass
    Msgbox .StringInfo
    .StringInfo = "Goodbye"
    Msgbox .RecordsetInfo.Fields.Count
    Msgbox .StringInfo
  End With
  Set MyClass = Nothing
End Sub

Featured Post

Industry Leaders: 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

621 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