-2

Help my code got wrong it says:

Either BOF or EOF is True, or the current record has been deleted,Requested operation requires a current record.

i think this rs.close has a problem or where can i set the rs.close? because i set and used recordset twice. anyone can help? please fix my code.



Public Function borrowersName(ByVal Iname, ByVal Imod, ByVal Icat, ByRef BFname, ByRef BLname) As Boolean

Dim dateReturned As String

'select firt the primary key of the item
qry1 = "select tblitem_id from tblitem inner join tblcategory on tblitem.tblcategory_id=tblcategory.tblcategory_id where tblitem.item_name='" + Iname + "' and tblitem.item_model='" + Imod + "' and tblcategory.category_name='" + Icat + "'"
rs.Open qry1, conn
qry1Result = rs.Fields(0).Value
rs.Close

qry2 = "SELECT date_returned,Firstname,Lastname FROM tblborrowers where tblitem_id='" & qry1Result & "' ORDER BY tblborrowers_id DESC LIMIT 1"
rs.Open qry2, conn

dateReturned = rs.Fields(0).Value

If dateReturned <> "" Then
  borrowersName = True
  BFname = rs.Fields(1).Value
  BLname = rs.Fields(2).Value
Else
  borrowersName = False
End If

Set rs = Nothing

End Function

illidan
  • 41
  • 1
  • 7
  • Been years since I worked on Vb6 so I won't attemt an answer but when you close rs with rs.Close you will (to my knowledge) not be able to Set rs with conn.Execute.. Please see MSDN documentation for Object.close http://msdn.microsoft.com/en-us/library/windows/desktop/ms675814(v=vs.85).aspx – Karl-Henrik Mar 10 '14 at 07:20
  • i changed it into rs.open qry2,conn but it still got wrong , :( – illidan Mar 10 '14 at 07:32
  • What error message do you get and for what line? – Karl-Henrik Mar 10 '14 at 07:43
  • it says :Operation is not allowed when the object is closed. – illidan Mar 10 '14 at 07:46
  • i think this rs.close code might be the problem..... – illidan Mar 10 '14 at 07:51
  • qry1Result = rs.Fields(0).Value.................. line. – illidan Mar 10 '14 at 07:54
  • @karl-henrik hey i edit my question .. and this new problem now occured. can u fixed it? – illidan Mar 10 '14 at 08:04
  • Honestly I think you need to go back and read on how to use ADO.NET with VB http://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110).aspx, from the top of my head I would guess that you are not getting any records so that rs.fields(0) does not exist – Karl-Henrik Mar 10 '14 at 08:10

1 Answers1

0

You do have the recordset Open and Close methods in the right order, so there is no problem there.

The error "Either BOF or EOF is True, or the current record has been deleted" simply means that one of your SELECT queries has returned zero records. What you do about that depends on your requirements. For example, you could test for Not rs.EOF before attempting to read a field value.

Christian Hayter
  • 30,581
  • 6
  • 72
  • 99