为什么不是 MS Access "item found in collection?"
Why isn't MS Access "item found in collection?"
我有一个未链接的 table "tblGrantRptData",我试图在其中修改字段记录以供后续过滤并导出到 EXCEL。我已确保所有字段名称拼写正确,但我仍然收到错误 3265,在此集合中找不到项目。
我已确认 MemmonthlyIncome 的拼写正确,并且在设计中被标识为 "currency."
这是显示字段名称的设计视图:
它停在这一行:
If IsNull (!MemmonthlyIncome) Then
错误 3265
如果我能得到一些帮助来解决这个问题,我想存储范围“0-30”....
下面的一个建议是“反编译”和“重新编译”。我读过当数据库在多个工作站上使用时这可能会导致问题。我修改了代码以到达一垒……有什么建议吗?
Private Sub cmdGenerateGrantRpt_Click()
'now run the qqAll query - this generates the tblGrantRptData - then close the query
DoCmd.SetWarnings False
DoCmd.OpenQuery "qqAll", acViewNormal, acEdit
DoCmd.Close acQuery, "qqAll"
DoCmd.SetWarnings True
'First set up the table: tblGrantRptData with the correct data in fields
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblGrantRptData", dbOpenTable)
'Check to see if the recordset actually contains rows and fill in particular values
With rs
If .EOF And .BOF Then
MsgBox "There are no records in this time interval"
Exit Sub
Else
.MoveFirst
Do Until .EOF = True
'Replace the monthly income with income categories
If IsNull(!MemmonthlyIncome) Then
.Edit
!MemmonthlyIncome = "0-30"
.Update
End If
Loop
End If
End With
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
End Sub
VBA 中没有 Is Null
表达式,而 SQL 中有。更改为 IsNull(rs!MemmonthlyIncome)
。
可能在记录集集合中引用了 Null,因此返回了错误。
在这种情况下,您在 IsNull(!MemmonthlyIncome)
收到错误 #3265,"Item not found in this collection" ...
Set rs = db.OpenRecordset("tblGrantRptData", dbOpenTable)
With rs
If IsNull(!MemmonthlyIncome) Then
如果 tblGrantRptData 不包含名为 MemmonthlyIncome 的字段,就会发生这种情况。您在 table 数据表视图中看到的列标题可能是字段的 Caption
属性。您可以在 table 的设计视图中检查字段的 Name
和 Caption
属性。或者您可以在即时 window 中列出 table 的实际字段名称。
这是我的 联系人 table:
中字段名称的缩写列表
set db = currentdb
for each fld in db.TableDefs("Contacts").Fields : ? fld.name : next
ID
Company
Last Name
First Name
您刚刚在设计视图中添加了 table 的屏幕截图...
请注意该字段名为 MemmothlyIncome,而不是 MemmonthlyIncome(moth 与 月)。所以这毕竟不是 Name
与 Caption
的区别;您只是尝试使用拼写错误的字段名称。该拼写问题在 DataSheet View 屏幕截图中也可见,但我们没有注意到它。
我有一个未链接的 table "tblGrantRptData",我试图在其中修改字段记录以供后续过滤并导出到 EXCEL。我已确保所有字段名称拼写正确,但我仍然收到错误 3265,在此集合中找不到项目。
我已确认 MemmonthlyIncome 的拼写正确,并且在设计中被标识为 "currency."
这是显示字段名称的设计视图:
它停在这一行: If IsNull (!MemmonthlyIncome) Then
错误 3265
如果我能得到一些帮助来解决这个问题,我想存储范围“0-30”....
下面的一个建议是“反编译”和“重新编译”。我读过当数据库在多个工作站上使用时这可能会导致问题。我修改了代码以到达一垒……有什么建议吗?
Private Sub cmdGenerateGrantRpt_Click()
'now run the qqAll query - this generates the tblGrantRptData - then close the query
DoCmd.SetWarnings False
DoCmd.OpenQuery "qqAll", acViewNormal, acEdit
DoCmd.Close acQuery, "qqAll"
DoCmd.SetWarnings True
'First set up the table: tblGrantRptData with the correct data in fields
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblGrantRptData", dbOpenTable)
'Check to see if the recordset actually contains rows and fill in particular values
With rs
If .EOF And .BOF Then
MsgBox "There are no records in this time interval"
Exit Sub
Else
.MoveFirst
Do Until .EOF = True
'Replace the monthly income with income categories
If IsNull(!MemmonthlyIncome) Then
.Edit
!MemmonthlyIncome = "0-30"
.Update
End If
Loop
End If
End With
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
End Sub
VBA 中没有 Is Null
表达式,而 SQL 中有。更改为 IsNull(rs!MemmonthlyIncome)
。
可能在记录集集合中引用了 Null,因此返回了错误。
在这种情况下,您在 IsNull(!MemmonthlyIncome)
收到错误 #3265,"Item not found in this collection" ...
Set rs = db.OpenRecordset("tblGrantRptData", dbOpenTable)
With rs
If IsNull(!MemmonthlyIncome) Then
如果 tblGrantRptData 不包含名为 MemmonthlyIncome 的字段,就会发生这种情况。您在 table 数据表视图中看到的列标题可能是字段的 Caption
属性。您可以在 table 的设计视图中检查字段的 Name
和 Caption
属性。或者您可以在即时 window 中列出 table 的实际字段名称。
这是我的 联系人 table:
中字段名称的缩写列表set db = currentdb
for each fld in db.TableDefs("Contacts").Fields : ? fld.name : next
ID
Company
Last Name
First Name
您刚刚在设计视图中添加了 table 的屏幕截图...
请注意该字段名为 MemmothlyIncome,而不是 MemmonthlyIncome(moth 与 月)。所以这毕竟不是 Name
与 Caption
的区别;您只是尝试使用拼写错误的字段名称。该拼写问题在 DataSheet View 屏幕截图中也可见,但我们没有注意到它。