How to replace dCount

P

paul

Hi,
For my Access 2000 application, I like to know the
number of records in a query, so I put this code:
intX = DCount("emp_no", "QueryName"), but the DCount seems
very slow.
Is there another way I can count the number faster than
DCount?
Thanks.
 
M

Michel Walsh

Hi,



intX=CurrentProject.Connection.Execute("SELECT COUNT(*) FROM
QueryName").Fields(0).Value



Hoping it may help,
Vanderghast, Access MVP
 
P

paul

Hi Michel,
Thanks for your help, may I ask what is "Fields
(0).value"? Is that a where clause? Since I don't need a
where condition, so I didn't include this, it complaint
about intX (type dismatch), which I define as integer.
 
M

Michel Walsh

Hi,


The type mismatch may occur if you don't have ADO in the references. You can
do it with DAO too, instead of trying to get it fixed with ADO, but do not
use CurrentDb (or it may be slow), use a reference to it:

---------------------
Dim db As CurrentDb : Set db=CurrentDb ' as a global variable, maybe...

....

intX=db.OpenRecordset("SELECT COUNT(*) FROM Table1", dbOpenForwardOnly,
dbReadOnly).Fields(0).Value
----------------------



Fields(0) takes the first field (of the first record of the recordset);
Fields(0).Value takes the value of the first field.



Hoping it may help,
Vanderghast, Access MVP
 

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

Similar Threads


Top