无法显示记录集

Trouble to display a recordset

Public Function `RecordsetSybase(sqlstr As String) As ADODB.Recordset
    If TestSybaseConnection() = False Then
        setLogin
    End If

    Dim commandObject As ADODB.Command
    Set commandObject = New ADODB.Command
    Dim data As New ADODB.Recordset
    With commandObject
        .CommandText = sqlstr
        .ActiveConnection = SybaseConnection(getUID, getPASS)
        .CommandTimeout = 350
    End With

    data.Open commandObject.CommandText, commandObject.ActiveConnection

    'Do Until data.EOF = True
    'MsgBox data(0)
    'data.MoveNext
    'Loop

    commandObject.ActiveConnection.Close

    Set RecordsetSybase = data
    Set commandObject = Nothing

End Function

Sub classific()

    Dim conn As WorkbookConnection
    Dim strSQL As String
    Dim rs As New ADODB.Recordset

   'Query
    strSQL = "SELECT DISTINCT name_short_orig, cl_rating " & _
             "FROM pbsm_hist.dbo.pbsm_auths_hist_adjusted " & _
             "WHERE name_short_orig IS NOT Null " & _
             "AND cl_rating NOT IN ('F+','F','Z') "

    Set rs = RecordsetSybase(strSQL)
    MsgBox rs  
End Sub

我可以在函数中显示记录集(见评论)。 但是我不能在子程序中执行此操作,我收到以下错误消息:

Run-time error '13': Type mismatch

您完全绕过了命令对象,目前它只是坐在那里存储命令文本和连接。

实际上 use the command object:

set data = commandObject.execute()

至于错误,MsgBox rs 无效 - 您希望看到 rs 对象的字符串表示形式是什么?

如果您想要第一个值:

if not rs.eof then msgbox rs.collect(0)