Counting Records

G

Guest

Is there an easy way to display, on a form, the number of records with the
same date as the date control on that form? If I have an unbound text box
called txtCount, how could I count the records behind the form using the
criteria in the txtDate control? Thanks...
 
F

fredg

Is there an easy way to display, on a form, the number of records with the
same date as the date control on that form? If I have an unbound text box
called txtCount, how could I count the records behind the form using the
criteria in the txtDate control? Thanks...

=DCount("*","TableName","[DateFieldName] = #" & [txtDate] & "#")
 
G

Guest

Put this in the control source of txtCount
=Dcount("*","MyTable", "[DateField] = #" & txtDate & "#")

In most cases a DCount will execute faster if you use "*" rather than a
specif fieldname to count.
 
G

Guest

Hi Don,

try;

=DCount("RecordID","UnderlyingTable/QueryNameHere","DateFieldName = #" &
Me.txtDate & "#")

or similar in the After Update event of the field that selects the current
record.

hope this helps,

TonyT..
 
K

kingston via AccessMonster.com

You can do something like this with the DCount() function:

txtCount = DCount("*","
","[DateField]=#" & Me.txtDate & "#")

However, this gets complicated if you want only records pertaining to a form
because of filters. You can replace "Table" with [Forms]![FormName].Form.
RecordSource, but that might not help if your users apply filters to the form.
 
D

Douglas J. Steele

Not only that, but if you select a field name, DCount only counts the rows
where that field is non-null.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
Put this in the control source of txtCount
=Dcount("*","MyTable", "[DateField] = #" & txtDate & "#")

In most cases a DCount will execute faster if you use "*" rather than a
specif fieldname to count.

Don said:
Is there an easy way to display, on a form, the number of records with
the
same date as the date control on that form? If I have an unbound text
box
called txtCount, how could I count the records behind the form using the
criteria in the txtDate control? Thanks...
 
M

Marshall Barton

Don said:
Is there an easy way to display, on a form, the number of records with the
same date as the date control on that form? If I have an unbound text box
called txtCount, how could I count the records behind the form using the
criteria in the txtDate control? Thanks...


You got four replies all suggesting the essentially the same
thing, but be aware the those will only work if the system
is set to use US style dates. If there is any chance that
one of your users may use a different date setting, then you
should use:

.... ,"[DateFieldName]=" & Format(txtDate,"\#m\/d\/yyyy\#")
 

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

Similar Threads


Top