Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty Recordsets

Status
Not open for further replies.

ngreenleaf

Programmer
Jan 13, 2003
24
US
I am trying to find a good way to deal with an empty record set. I was using a DAO recordset, but when it is empty a MoveFirst does not work. It seems that issuing a MoveFirst would be safer than trusting that the pointer is initialized at the top of my recordset. I noticed that in ADO there is a BOF as well as EOF (but I didn't see such a thing in DAO) and you could test them and only issue the MoveFirst is they are not equal (eg empty set). I have discovered that there are issues with using RecordCount in DAO. Apparently the value 0 is accurate in indicating that the set is empty, but getting the actual count requires a MoveLast/MoveFirst. As a result I am not comfortable with using RecordCount.

Is RecordCount reliable... in which case I could do:

If abc.RecordCount <> 0 then abc.MoveFirst

Or is ADO better using...

IF abc.BOF <> abc.EOF then abc.movefirst

Or is issuing the movefirst totally unnecessary because it is a guarantee that when you do OpenRecordset it will be pointing at the first record?

I'm sure this is a style question to some extent... but I am interested in your solutions.
 
Let me reply to my own question... DAO does have a BOF property as well (I missed it before). As a result my preference if:

if (not abc.BOF)or (not abc.EOF) then
abc.movefirst
end if

I also prefer to do the move and not trust the record to come initialized correctly for me. But anyone else's thoughts would be interesting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top