In this tutorial you will learn how to use the DCOUNT Function.
Take an example Table of Customers.
CustomerT
CustomerID
FirstName
LastName
Phone
CustomerSince
CreditLimit
DaysGrace
IsActive
1
Richard
Rost
7165557777
01/01/2012
1001
1
True
2
Joe
Smith
7165553434
01/03/1990
500
5
True
3
Suzan
Jones
5624365146
02/01/1998
1500
2
False
4
Alan
Watson
4193891212
17/05/2012
50
3
True
5
Anna
Picore
713236479
05/05/2005
1020
4
True
6
Ronald
Simms
7807465468
04/04/1992
50
2
True
7
Donald
Barker
4164415555
01/03/1998
250
5
True
8
Benny
Sperduti
7167267262
06/04/1999
1600
7
False
9
Pete
Smith
5645597777
04/04/2000
500
3
False
10
Barbra
Peters
8292827288
31/12/2005
50
1
True
11
Joe
Jones
5495465466
01/06/2004
500
3
True
14
Pezz
Dispo
26/09/2012
0
4
True
16
Bob
Smith
04/10/2012
0
9
True
In this example we want to find out how many Customers have a Credit Limit equal to 50 so we set the Field
to * to choose any/all Fields in the Table, the Domain is CustomerT as this is the Table we are searching and
the Criteria of "CreditLimit=50" as this is the Field name we are searching on.
The DCOUNT function returns an integer from a specified set of records (or domain) containing
the number of records in that search.
=DCOUNT(Field, Domain, Criteria)
Query
The results using a Query would be
SELECT * FROM CustomerT WHERE CreditLimit = 50
tblNames
CustomerID
FirstName
LastName
Phone
CustomerSince
CreditLimit
DaysGrace
IsActive
4
Alan
Watson
4193891212
17/05/2012
50
3
True
6
Ronald
Simms
7807465468
04/04/1992
50
2
True
10
Barbra
Peters
8292827288
31/12/2005
50
1
True
FORM
In a Form you could set the Default Value of a Textbox to
=DCount("*", "CustomerT", "CreditLimit=50")
VBA
In a Form add a TEXTBOX control and rename it "txtDCount", then you could add the following in the Load Event.
Private Sub Form_Load()
txtDCount = DCount("*", "CustomerT", "CreditLimit=50")
End Sub