ms-access - 在与请求的名称或序号相对应的集合中找不到项目
问题描述
尝试自动生成销售 ID。但我不知道为什么我会收到这个错误。
Set qs = New ADODB.Recordset
qs.Open "select * from DailyRecords ", db, 3, 2
With qs
If .RecordCount = 0 Then
txtsalesID.Text = "S-0001"
Else
qs.MoveLast
txtsalesID.Text = "S-" & Format(Right(qs!SalesID, 4) + 1, "0000") // this line is producing the error
End If
我什至检查了数据库字段名称。它与 SalesID 相同。我尝试了很多并寻求帮助
解决方案
我认为问题在于您RecordCount
用来检查记录集是否为空。将RecordCount
光标留在记录集的末尾,因此即使有记录,您也无法从记录中读取数据。您应该EOF
改用:
If .EOF Then
txtsalesID.Text = "S-0001"
Else
qs.MoveLast
txtsalesID.Text = "S-" & Format(Right(qs!SalesID, 4) + 1, "0000")
End If
推荐阅读
- python - 计算因子之间相关性的正确方法
- python - Python 扩展在 & 命令的 vscode bc 中不起作用
- javascript - 使href中的每个锚标记都带有哈希(#) unclickabe
- flutter - flutter : android 或 ios 手机打开时在后台启动应用程序
- react-native - 即使重新渲染后标记也不会在地图上移动
- javascript - React 包装器组件未按预期工作
- postgresql - 在 Haskell 中将值列表传递给 SELECT PostgreSQL 查询
- cloudflare - Cloudflare:找不到您的访问组织
- model - OpenBUGS:层次模型无法编译
- go - 如何查明“不允许导入周期”的问题?