无法在与请求的名称或序号对应的集合中找到item [英] item cannot be found in collection corresponding to the requested name or ordinal

查看:190
本文介绍了无法在与请求的名称或序号对应的集合中找到item的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求帮助,尝试修复我在excel vba代码中的错误。我试图将sql表的列名导入excel工作表。当我运行此代码时:


[For intCount = 0 to rsmyf.Fields.Count

Range(" A2")。Offset(intCount,0 ).Value = rsmyf(intCount).Name]


我收到此错误:运行时错误''3265'' - 在请求的名称对应的集合中找不到项或序数。错误出现在这里 - " .Name"


有人能告诉我需要做些什么来解决这个问题吗?

解决方案

< blockquote> rsmyf(intCount)这会尝试访问当前记录中字段的值。


你是什么可能尝试做的是访问该字段本身。 rsmyf.Fields(intCount)


我对rsmyf.Fields(intCount)进行了更改,现在我收到以下错误:


运行时错误''1004'':BOF或EOF为True,或者当前记录已被删除。请求的操作需要当前记录。


我将代码更改回来:


[对于intCount = 0到rsmyf.Fields.Count

范围(" A2")。偏移量(intCount,0).Value = rsmyf(intCount).Name]


它给了我列名我在excel电子表格中的正确位置引用的sql表,但它仍然是错误,不会继续我的其余代码。


I am seeking help to try and fix an error that I am getting inside of my excel vba code. I am trying to import the column names of a sql table into an excel worksheet. When I run this code:

[For intCount = 0 To rsmyf.Fields.Count
Range("A2").Offset(intCount, 0).Value = rsmyf(intCount).Name]

I get this error: Run-time error ''3265''- Item cannot be found in the collection corresponding to the requested name or ordinal. The error appears here - ".Name"

Can someone tell me what I need to do to fix this?

解决方案

rsmyf(intCount) This attempts to access the value of the field at the current record.

What you''re probably trying to do is access the field itself. rsmyf.Fields(intCount)


I made the change to rsmyf.Fields(intCount)and now I get the following error:

Run-time error ''1004'': Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.


I changed my code back to this:

[For intCount = 0 To rsmyf.Fields.Count
Range("A2").Offset(intCount, 0).Value = rsmyf(intCount).Name]

It gave me the column names of the sql table that I am referencing in the correct location in my excel spreadsheet, but it still errors and will not continue with the rest of my code.


这篇关于无法在与请求的名称或序号对应的集合中找到item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆