记录集问题
我在让我的记录集在以下代码中正常工作时遇到问题,并且不确定这是否是 VBA 固有的破烂部分的个人运行时错误。代码如下
Option Compare Database
Option Explicit
Dim dbInquiry As New ADODB.Connection
Dim rstVendor As New ADODB.Recordset
Private Sub Form_Load()
Set dbInquiry = CurrentProject.Connection
rstVendor.Open "Select * from Vendors Order By VendorName", dbInquiry, adOpenKeyset, _
adLockOptimistic, adCmdText
Me.lstVendors = rstVendor!VendorNo
Me.lstVendors.Requery
Call readVendor
End Sub
Private Sub readVendor()
Me.lblVendorNumber.Caption = rstVendor!VendorNo
Me.lblVendorName.Caption = rstVendor!VendorName
Me.lblVendorAddress.Caption = rstVendor!Address1
Me.lblVendorCity.Caption = rstVendor!City & ", " & rstVendor!Prov
Me.lblVendorPostal.Caption = rstVendor!PostCode
End Sub
Private Sub lstVendors_Click()
rstVendor.MoveFirst
rstVendor.Find "VendorNo = " & Me.lstVendors
Call readVendor
End Sub
现在,问题在于读取数据库。当在表单加载时调用 readVendor 方法时,它可以完美运行。当单击第一个项目时调用它时,我收到错误 3021:BOF、EOF 或记录已删除。非常感谢任何指导。提前致谢
I'm having an issue getting my recordset to work properly in the following code, and am unsure if its a personal runtime error of part of the inherent shabbiness of VBA. the code is as follows
Option Compare Database
Option Explicit
Dim dbInquiry As New ADODB.Connection
Dim rstVendor As New ADODB.Recordset
Private Sub Form_Load()
Set dbInquiry = CurrentProject.Connection
rstVendor.Open "Select * from Vendors Order By VendorName", dbInquiry, adOpenKeyset, _
adLockOptimistic, adCmdText
Me.lstVendors = rstVendor!VendorNo
Me.lstVendors.Requery
Call readVendor
End Sub
Private Sub readVendor()
Me.lblVendorNumber.Caption = rstVendor!VendorNo
Me.lblVendorName.Caption = rstVendor!VendorName
Me.lblVendorAddress.Caption = rstVendor!Address1
Me.lblVendorCity.Caption = rstVendor!City & ", " & rstVendor!Prov
Me.lblVendorPostal.Caption = rstVendor!PostCode
End Sub
Private Sub lstVendors_Click()
rstVendor.MoveFirst
rstVendor.Find "VendorNo = " & Me.lstVendors
Call readVendor
End Sub
Now, the issue is with reading the database. When method readVendor is called on form load, it functions perfectly. when it is called on lst item click, i get Error 3021: Either BOF, EOF or record deleted. Any guidance very much appreciated. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rstVendor.Find "VendorNo = " & Me.lstVendors
被发现了?和/或 rstVendor 仍然开放吗?
rstVendor.Find "VendorNo = " & Me.lstVendors
was something found? and/or is rstVendor still open?