SQL Recordset

M

MK

Hello

I want to know the number of records that an SQL statement will produce. I have been told that it is best to feed the SQL into a recordset and then look at the record count of that

I've not been able to get the code to work in VBA, so could someone please help me

Many thanks

MK
 
C

Chris Nebinger

You probably don't want to open a recordset. The only way
to get an accurate count that way is to open the
recordset, scroll to the end, then get the count. This is
alot of overhead.

Instead, use the Count SQL Statement along with the SQL
code:


set rst = currentdb.openrecordset("Select Count(*) from
[Select ... Your statement) as Recordset")

intRecordCount=rst(0)



Chris Nebinger




-----Original Message-----
Hello,

I want to know the number of records that an SQL
statement will produce. I have been told that it is best
to feed the SQL into a recordset and then look at the
record count of that.
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could also use the DCount() function:

dim lngRecords as Long
lngRecords = DCount("*","query name")
debug.Print lngRecords

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQI62d4echKqOuFEgEQJjngCguJacJ7q/QRb0fEjM5TVG+r50uQ4AoKjK
KrXYuzrsmfjQh7Z1EkEzTT5W
=JKoz
-----END PGP SIGNATURE-----
 

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