Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a recordset being passed from a COM object

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
VB Rookie here,

I have created an ActiveX DLL in VB 6.0 that uses an interface and passes a recordset. It looks something like this:

Code:
Private Function IClient_getClients() As ADODB.Recordset
    Dim sql, login_Name As String
    On Error GoTo ErrHandler
    
    Call openConnection(adoConnection)
    If (adoConnection.State) Then
        sql = "select * " & _
              "from client_info " & _
              "order by client_name"
        Call openRecordSet(adoConnection, IClient_getClients, sql)
        Set IClient_getClients = adoRecordset
        
'~~~~~~~~~~ Close the recordset ~~~~~~~~~~
        Call closeConnection(adoRecordset)
    End If
        
'~~~~~~~~~~ Close the database connection ~~~~~~~~~~
    Call closeConnection(adoConnection)
    Exit Function

ErrHandler:
    If Err.Number <> 0 Then MsgBox Err.Description
    Exit Function
End Function
[\code]

When I try to receive the recordset from the object in my form I'm getting an error that is basically letting me know that I'm not using the correct syntax.  This is what I have in my form to access the recordset from the COM object:

[code]
Private Sub Form_Load()
    Dim rs As New ADODB.Recordset
    Dim objClients As TimeCard.IClient
    Set objClients = New TimeCard.CClient
    
    Set rs = objClients.getClients
    
        Do Until rs.EOF
            cmbClients.AddItem rs!client_Name
            cmbClients.ItemData(cmbClients.NewIndex) = rs!client_UID
            rs.MoveNext
        Loop
End Sub
[\code]

This is wrong, I know, but I'm having trouble finding helpful documentation that explains how to do it correctly.  If anyone can offer some assistance here, it would be greatly appreciated.  A pathetically easy problem for the average pro to figure out, but a showstopper for a rookie such as myself.  

Thanks,
- VB Rookie
 
I'm just getting into COM objects myself. You have:

Private Function IClient_getClients() As ADODB.Recordset

Shouldn't this be a Public function? Colin Chevrier
Colin_Chevrier@dmr.ca

 
Firstly, the function is Private, as it implements the public method of the interface.

Could you provide the error message you are getting? I've looked at your code, but can't see anything immediately wrong with it. I am tired tho...

Chaz
 
I believe that I have it figured out. I retooled my class and now I'm referencing it from the form as such:

Code:
Dim objClients As TimeCard.IClient
Set objClients = New TimeCard.CClient
    
    objClients.getClientInfo
    Do While Not (objClients.EOF)
        cmbClients.AddItem objClients.clientName
        cmbClients.ItemData(cmbClients.NewIndex) = objClients.clientUID
        objClients.MoveNext
    Loop
    Set objClients = Nothing

I had to add a property for EOF and a method for MoveNext to my interface and corresponding logic in the class. Works like a charm now.

Thanks for your help,
- VB Rookie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top