记录集问题

发布于 2024-11-02 03:47:37 字数 1080 浏览 0 评论 0原文

我在让我的记录集在以下代码中正常工作时遇到问题,并且不确定这是否是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事与诗 2024-11-09 03:47:37

rstVendor.Find "VendorNo = " & Me.lstVendors

被发现了?和/或 rstVendor 仍然开放吗?

rstVendor.Find "VendorNo = " & Me.lstVendors

was something found? and/or is rstVendor still open?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文