ms-accessms-access-2007vba

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.


Solution

  • 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.