ADO test for empty recordset

B

BillyRogers

How do i test a recordset before using the fields? Can you simply test for

If not (rst.eof) and not (rst.bof) then

debug.print rst.fields(0)

End If

My only concern with this test is that I don't know if a recordset can open
at EOF or BOF even if it's not empty. I only want to skip empty recordsets
to avoid errors. My recordset is a SQL query.


--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003
 
D

Dirk Goldgar

BillyRogers said:
How do i test a recordset before using the fields? Can you simply
test for

If not (rst.eof) and not (rst.bof) then

debug.print rst.fields(0)

End If

My only concern with this test is that I don't know if a recordset
can open at EOF or BOF even if it's not empty. I only want to skip
empty recordsets to avoid errors. My recordset is a SQL query.

If you *know* the recordset has just been opened, then you need only
check for either rst.EOF or rst.BOF. The recordset will be opened at
the first record, if there are any records in it. However, if there's
any question that the recordset's current record pointer may have been
moved since it was opened -- and especially if you've just been handed a
recordset from somewhere -- checking for both conditions is the right
way to do it.
 

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