Application.DCount (Access)

You can use the DCount function to determine the number of records that are in a specified set of records (a domain).

For example, you could use the DCount function in a module to return the number of records in an Orders table that correspond to orders placed on a particular date. Use the DCount function to count the number of records in a domain when you don't need to know their particular values. Although the expr argument can perform a calculation on a field, the DCount function simply tallies the number of records. The value of any calculation performed by expr is unavailable. Use the DCount function in a calculated control when you need to specify criteria to restrict the range of data on which the function is performed. For example, to display the number of orders to be shipped to California, set the ControlSource property of a text box to the following expression:

DCount (Expr, Domain, Criteria)


=DCount("[OrderID]", "Orders", "[ShipRegion] = 'CA'")

Arguments

The following arguments are required:

Expr (String) - An expression that identifies the field for which you want to count records. It can be a string expression identifying a field in a table or query, or it can be an expression that performs a calculation on data in that field. In expr, you can include the name of a field in a table, a control on a form, a constant, or a function. If expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.

Domain (String) - A string expression that identifies the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.

Optional arguments

The following argument is optional

Criteria (String) - An optional string expression used to restrict the range of data on which the DCount function is performed. For example, criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If criteria is omitted, the DCount function evaluates expr against the entire domain. Any field that is included in criteria must also be a field in domain; otherwise, the DCount function returns a Null.