簡體   English   中英

Range.Recordset方法的自動化錯誤

[英]Automation Error with Range.Recordset method

我在執行以下代碼行時遇到一個問題,該行包含在一個用戶窗體中:

 Dim RS As ADODB.Recordset
 Set RS = CreateObject("ADODB.RecordSet")

 'omitting the queryString and connection parameters - I'm highly certain 
  the issue doesn't lie there

 RS.Open queryString, cn

 'Declare the object
 Dim classCutCells As Range

 'The next 2 lines are 1 in the actual code, just broke it up here for readability
 Set classCutCells = reisWS.Range(reisWS.cells(classCutRow, classCutCol),  _
     _ reisWS.cells(classCutRow + RS.RecordCount, classCutRow + RS.Fields.Count))

 'The following line produces the error
 classCutCells.CopyFromRecordset (RS)

當click事件關閉時,出現此錯誤:

Run-time error '430': Class does not support Automation or does not support expected interface.

我目前的參考資料包括:

Visual Basic for Applications
Microsoft Excel 14.0 Object Library
OLE Automation
Microsoft Forms 2.0 Object Library
Microsoft Office 14.0 Object Library
Microsoft Scripting Runtime
Microsoft Windows Common Controls 6.0 (SP6)
Microsoft Visual Basic for Applications Exentisibility 5.3
Microsoft ActiveX Data Objects 6.0 Library

當我進行調試時,將classCutCells.CopyFromRecordset(RS)傳遞到即時窗口中時,代碼可以正常運行,並且數據被放入所需的范圍內。 我認為這可能是參考問題,但是經過幾天的瀏覽卻沒有在網上找到任何東西。 有任何想法嗎?

顯然,當您用括號調用CopyFromRecordset(RS)方法時,它需要一個變體。 我將RS從括號中移出,現在可以使用了。 如果只有我遇到類型錯誤而不是此自動化錯誤,上周該問題將得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM