check for empty recordset
Posted on 2002-06-04
I am trying to check an open recordset to see if it returned any rows or not, if it returns one or more, I want to do something, if it's empty I want to do something else. Here is my code.
Set db = OpenDatabase(MydbName)
mySQL = "select DocNum from tblReleasedWOLots where LotNum = '" & txtLotNum.Text & "'"
rstWO = db.OpenRecordset(mySQL)
If rstWO.count > 0 Then
'found the LotNum record, now do some stuff here
'lot number not found in database, do other stuff
The SQL is set up so that it will only return one record, but even if I put in criteria that will return no records, rstWO.count is always returning '1' (in the debug) so it never hits the 'else' of the if statement.
What am I doing wrong? It's VB6 I'm using and the database is Access97