RecordCount problem

T

Terence

Hi,

In my macro, I created an ADO recordset to hold the data.
But why I always get -1 when I use "rst.RecordCount" even
though the recordset is not empty?
Anyone knows?
Thanks a lot.

Terence
 
R

Rob Bovey

Hi Terence,

Unless you use a cursor that builds the entire recordset in advance
there's no way to get a record count because the records haven't been
retrieved yet. Even with a scrollable cursor, you'll usually have to execute
an rs.MoveLast followed by an rs.MoveFirst in order to fully populate the
recordset so that a count can be retrieved.

This can be a pretty resource intensive operation. If you really need to
know in advance exactly how many records you're going to get back, it's
often better to do a separate SELECT COUNT(*) query using the conditions in
your final SQL statement. The result of this query will be the number of
records returned when you execute the full SELECT statement.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 

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