Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA:记录集.Fields“;对象没有';“我不支持这项财产”;_Vba_Excel_Excel 2007_Ado_Adodb - Fatal编程技术网

VBA:记录集.Fields“;对象没有';“我不支持这项财产”;

VBA:记录集.Fields“;对象没有';“我不支持这项财产”;,vba,excel,excel-2007,ado,adodb,Vba,Excel,Excel 2007,Ado,Adodb,我试图遍历每个记录集上的字段,并将它们的值添加到我的Excel2007工作表中 我有下面的代码,但每当对象到达“时,我会得到”对象不支持此属性“ 我错过什么了吗?我是否需要在VBA中添加其他引用以使用.Fields?我目前正在引用中使用Microsoft ActiveX Data Objects 6.0库。SQL查询Oracle数据库,但我认为这与此错误无关 Set recSet = newConn.getOpenIncidents("exampleworkgroup") Set Path =

我试图遍历每个记录集上的字段,并将它们的值添加到我的Excel2007工作表中

我有下面的代码,但每当对象到达“时,我会得到”对象不支持此属性“ 我错过什么了吗?我是否需要在VBA中添加其他引用以使用.Fields?我目前正在引用中使用Microsoft ActiveX Data Objects 6.0库。SQL查询Oracle数据库,但我认为这与此错误无关

Set recSet = newConn.getOpenIncidents("exampleworkgroup")
Set Path = ThisWorkbook.Worksheets("Incidents")
iRow = 2

With Path
    iCol = 1
    For Each x In recSet.Fields
        .Cells(iRow, iCol).Value = x.Value  'Customer Name
        iCol = iCol + 1
    Next
End With 
这是我的类中函数的代码

Public Function getOpenIncidents(ByVal wrkgp As String)
    Set rs = New ADODB.Recordset
    Dim SQL As String

    SQL = "SELECT intbl.cust_ky, intbl.incid_id, intbl.OPEN_TS, intbl.CLOSE_TS, wrkgptbl.wrkgp_id, intbl.incid_ttl_dn " _
        & "FROM (MAIN.testtable intbl INNER JOIN MAIN.wrkgrp wrkgptbl ON intbl.curr_wrkgp_ky=wrkgptbl.wrkgp_ky) " _
        & "WHERE wrkgptbl.wrkgp_id='" & wrkgp & "'"

    rs.Open SQL, con, adOpenKeyset
    rs.MoveFirst
    getOpenIncidents = rs

End Function

我想我已经发现了
recSet
实际上是字段类型。因此,没有像
那样的
.Fields
属性。Fields
是记录集对象的属性

解决方案应该是:

For Each x In recSet

或者更改
getOpenIncents()
方法以返回记录集(包括将返回行更改为
Set getOpenIncents=rs
)。

如果尝试
recSet.Fields.Count
在For Each之前,会发生什么情况?
recSet
实际上是记录集吗?您的
getOpenEvents()
函数返回一个变量,并且函数中也没有
Set
。@creamyegg我没有将recSet声明为记录集。但它不应该是从函数中获取变量后的一个吗?我在recSet上添加了手表,可以看到其中的6个项目。我如何迭代这6个项目?@p.campbell我试过了。收到相同的错误“Object不支持此属性或方法”:((我收到recSet的“Object不支持此属性或方法”。也关闭。开始怀疑我是否使用了正确的引用,或者是否需要添加其他引用。