Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a query record count in a form control

I have a query that returns a fluid # of records, depending on criteria selected in the form. I would like to display the total # of records returned to the form.

I have added a unbound text field to the footer in the form that is displaying the controls and resulting records. I tried the following expressions in the text field, both of which result in #error:

=Count([qrnname]![fieldtocount])
=DCount([qrnname]![fieldtocount])

This should be simple.

like image 201
jamesTheProgrammer Avatar asked Oct 11 '25 21:10

jamesTheProgrammer


2 Answers

DCount requires string values for its arguments. Assuming fieldtocount is the name of a field returned by the named query qrnname, use this as your text box's Control Source ...

=DCount("[fieldtocount]", "qrnname")

Since that query depends on criteria selected in the form, Requery the text box whenever those criteria change to update the count displayed in the text box.

like image 69
HansUp Avatar answered Oct 14 '25 16:10

HansUp


use this =DCount([fieldtocount]![qrnname])

The syntax for the DCount function is:

DCount ( expression, domain, [criteria] )

expression is the field that you use to count the number of records.

domain is the set of records. This can be a table or a query name.

criteria is optional. It is the WHERE clause to apply to the domain.

Dcount in detail

like image 22
Santosh Avatar answered Oct 14 '25 16:10

Santosh