ADODB Recordset.RecordCount给出错误答案

时间:2015-05-11 14:10:13

标签: vba excel-vba adodb excel

我的Recordset返回-1作为RecordCount时出现问题,实际上有1164条记录。

我检查了我的查询,这很好。即使它告诉我有-1条记录,CopyFromRecordset方法仍然有效并粘贴正确的结果。在使用rs.RecordCount之前从未遇到过问题?

Dim strSQL As String
Dim rs As New ADODB.Recordset

If cust = "JPM" Then
    port = "RP L99"
Else
    port = "RP V10"
End If

strSQL = "my select query"

rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
GetCompanies = rs.RecordCount
If GetCompanies > 0 Then
   wsLive.Range("A" & ROWCOMPANYSTART).CopyFromRecordset rs
   wsLive.Range("C" & ROWCOMPANYSTART & ":C" & GetCompanies + ROWCOMPANYSTART).NumberFormat = "0.00%"
End If
CloseRecordset rs

End Function

0 个答案:

没有答案