Code for Counting Records and Display in Form

L

Les Kyser

This is the formula to use in the control portion of a
form's text box if you want to display a count of the
number of records that contain a particular entry (say
Field_Entry) in a particular field (say Field_Name) of a
particular query (say qryQuery_Name). Just replace
Field_Entry with the actual field entry, replace
Field_Name with the actual field name, and replace
qryQuery_Name with the actual name of the query you are
using for the record count operation.
=DCount("[Field_Name]","qryQuery_Name"," [Field_Name]
='Field_Entry'")
Note: The quote marks have to be the straight line quote
marks as contained in the Access Help file ( like " and ').
To enter the above expression you must be in design mode
and select the control portion of the text box and go to
properties. Then enter this expression in the "Control
Source" line on the properties list. If entered with the
(), [], commas, double-quotes, and single-quotes and no
spaces as shown above it will work! You may be able to get
away with some spaces on either side of a comma or on
either side of an equal sign, but the surest way is to use
the above form exactly as it's shown. Notice that you have
to enter the Field_Name in two different parts of the
formula.
 

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

Top