rs.EOF错误可以任何人检查和修复它请

时间:2014-03-07 05:07:18

标签: vb6 vb6-migration

任何人都可以检查我的代码并修复它吗?因为 我认为((如果rs.EOF))附近有一个问题,因为我使用这种方法2次。 如果我运行它我得到这个错误:

错误:对象打开时不允许操作。


Public Sub addBorrower(BCat As String, BIname As String, BImod As String, BFname As String, BLname As String, BBD As String, BDR As String)

    Dim itemid As Integer

    qry2 = "select tblItem_id,item_name,item_model,category_name from tblitem inner join tblcategory on tblcategory.tblcategory_id=tblitem.tblcategory_id where tblitem.item_name='" + BIname + "' and tblitem.item_model='" + BImod + "' and tblcategory.category_name='" + BCat + "'"

    Set rs = conn.Execute(qry2)

    If Not rs.EOF Then 

        itemid = rs.Fields(0).Value
        qry1 = "select * from tblborrowers where tblItem_id=' + itemid + '"
        rs.Open qry1, conn

        If Not rs.EOF Then

            DateReturned = rs.Fields(5).Value
            If DateReturned = Null Then
                MsgBox "Cant add the Borrowers to the item because there's some user who used it that hav'nt returned Yet."
            Else
                qry1 = "insert into tblborrowers(Firstname,Lastname,tblItem_id,date_Borrowed,date_Returned)values('" + BFname + "','" + BLname + "','" + itemid + "','" + BDD + "','" + BDR + "')"
                MsgBox "Successfully added"
            End If

        Else
            qry1 = "insert into tblborrowers(Firstname,Lastname,tblItem_id,date_Borrowed,date_Returned)values('" + BFname + "','" + BLname + "','" + itemid + "','" + BDD + "','" + BDR + "')"
            MsgBox "Successfully added"
        End If

    Else
        MsgBox "Sorry the Item category,Item name and Item model did'nt match or exist. Please check.", vbCritical, "Notification"
    End If

    Set rs = Nothing

End Sub

1 个答案:

答案 0 :(得分:1)

你犯了很简单的错误。

您已在此处打开Recordset

Set rs = conn.Execute(qry2)

而且,你再次在这里打开相同的记录集RS

qry1 = "select * from tblborrowers where tblItem_id=' + itemid + '"
    rs.Open qry1, conn

如果您想再次打开Rs,请先关闭它。这就是为什么它说:     对象打开时不允许操作。

rs.Close
qry1 = "select * from tblborrowers where tblItem_id=' + itemid + '"
    rs.Open qry1, conn

或者,使用另一个Recordset。