我的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