How to check the result

Q

QVSGLAM

Hi, all,
In A2K VBA, after executed a select query command, how can I check
if there is data in the result set?
Thank you.
GL
 
D

Douglas J Steele

If (rst.BOF = True) And (rst.BOF = True) Then
' there's nothing in the recordset
End If

Realistically, it's probably sufficient only to check rstEOF = True.

rst.RecordCount = 0 is also a valid check (although you can't rely on
RecordCount for an accurate count of records until you move to the end of
the recordset)
 
R

Robert Morley

Actually, whether or not RecordCount will be reliable depends on the
context.

If it's a DAO recordset and you're opening a table directly, it will be
accurate even if you haven't traversed the recordset. I believe there are
one or two other instances when it's accurate without having to do a
MoveLast (maybe in ordered recordsets where it has to run the whole thing
anyway?), but as Doug says, you're generally best assuming you should move
to the last record before relying on RecordCount as accurate.

If it's an ADO recordset, I don't believe it's ever accurate when first
opened until you've hit the last record (unless, of course, it's a 0- or
1-record set).

In any of the above instances, though, RecordCount should be 1 or more if
there is at least one record in the set, and should be 0 only if there are
none.



Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top