How to replace dCount

  • Thread starter Thread starter paul
  • Start date Start date
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.
 
Hi,



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



Hoping it may help,
Vanderghast, Access MVP
 
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.
 
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
 
Back
Top