How do I use DCOUNT

D

Dan

Hi;

I'm trying to count the number of records in a table. I
understand DCOUNT is what I need to use but I can't get
it right. I'm doing this:

DCOUNT("*","Beans") But the compiler doesn't like this.

When I get that to work, can I then do something like
this?

If DCOUNT > 10

Thanks
 
M

Michael Daly

Dan

You need a variable to pass the value into or returned
from the DCount function.

e.g.

Dim lvTableCount as Integer ' Create a local _
variable called _
TableCount to store _
the returned data.

' Populate the local variable with a count of all records _
from the table 'Beans'.
lvTableCount = DCount("*","Beans")

' For debuging purposes display the returned # of Records.
MsgBox "The number of records in table 'Beans' = " &
lvTableCount

' The next part works with the data in your local variable.
If lvTableCount > 10 then
' Do this...
End If

Good luck.

Michael Daly
23 Sept 2003
 
F

Fredg

What is "Beans"?
The name of the table? The name of a Field?

As a Control's Control Source:

= DCount("*","YourTableName")

will count all the records in the table.
If "Beans" is the name of the table, then your DCount should work.

However if "Beans" is the name of a Field, then it will not work.

Let's assume "Beans" is the name of a field in the table.
Then you could use:

=DCount("*","YourTableName"."[Beans] > 10")

To count how many records have more than 10 in the [Bean] field.

If this is being done in VBA then you would need:
Dim intCount as Integer
intCount = DLookUp("*","YourTableName","[Beans] >10")
 

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