vba - 此集合中未找到项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15748576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:21:04  来源:igfitidea点击:

vba - item not found in this collection

vbaaccess-vba

提问by Lan

I keep keep getting Run-time error '3265':

我不断收到运行时错误“3265”:

Item not found in this collection for rstAnswers("20GBRank") = irank while it works in other db.

在此集合中找不到 rstAnswers("20GBRank") = irank 的项目,但它在其他数据库中工作。

What am I doing wrong? How can I fix it?

我究竟做错了什么?我该如何解决?

Option Compare Database
Option Explicit

Public Function Update20BldgRank()
Dim db As Database
Dim rstAnswers As Recordset
Dim i As Integer
Dim irank As Integer
irank = 1
Set db = CurrentDb()
Set rstAnswers = db.OpenRecordset("Top20Genbld13", dbOpenDynaset)
rstAnswers.MoveFirst
Do Until rstAnswers.EOF
rstAnswers.Edit
rstAnswers("20GBRank") = irank
rstAnswers.Update
rstAnswers.MoveNext
irank = irank + 1
Loop
rstAnswers.Close
Update20BldgRank = irank - 1
End Function

回答by Santosh

Just make sure field(column) 20GRankexist in db where you are getting the error.

只需确保在出现错误的数据库中存在field(column) 20GRank 即可