DCount by date range

  • Thread starter Hammond-Wandsworth
  • Start date
H

Hammond-Wandsworth

I'm trying to calculate a count of a date field for those records that have
been added in the past 7 days. I want to display this in a report header and
I am adding the following code to the expression builder within the control
source. The code, however, is not working. I need to calculate several fields
this way and the code is not working on any of them. An example is below:

=DCount("[Alleged Breach Date]","[Breach Table]","[Alleged Breach
Date]=TRUE")>Date()-"7"

Can anyone see any mistakes with this code? Please let me know where I'm
going wrong. Thanks.
 
T

Tom Lake

Hammond-Wandsworth said:
I'm trying to calculate a count of a date field for those records that
have
been added in the past 7 days. I want to display this in a report header
and
I am adding the following code to the expression builder within the
control
source. The code, however, is not working. I need to calculate several
fields
this way and the code is not working on any of them. An example is below:

=DCount("[Alleged Breach Date]","[Breach Table]","[Alleged Breach
Date]=TRUE")>Date()-"7"

Can anyone see any mistakes with this code? Please let me know where I'm
going wrong. Thanks.

Try this:

=DCount("[Alleged Breach Date]", "[Breach Table]", "[Alleged Breach Date] >
" & Date() - 7)

Tom Lake
 
J

John Spencer

The following should work
= DCount("*","[Breach Table]","[Alleged Breach Date]> Date()-7")




--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Tom Lake said:
Hammond-Wandsworth said:
I'm trying to calculate a count of a date field for those records that
have
been added in the past 7 days. I want to display this in a report header
and
I am adding the following code to the expression builder within the
control
source. The code, however, is not working. I need to calculate several
fields
this way and the code is not working on any of them. An example is below:

=DCount("[Alleged Breach Date]","[Breach Table]","[Alleged Breach
Date]=TRUE")>Date()-"7"

Can anyone see any mistakes with this code? Please let me know where I'm
going wrong. Thanks.

Try this:

=DCount("[Alleged Breach Date]", "[Breach Table]", "[Alleged Breach Date]
" & Date() - 7)

Tom Lake
 
T

Tom Lake

John Spencer said:
The following should work
= DCount("*","[Breach Table]","[Alleged Breach Date]> Date()-7")

Will it know enough to expand the Date() if it's inside the quotes?

Tom Lake
 
J

John Spencer

Obviously I think so or I wouldn't have posted it that way. And my testing
indicates that it does. ;>)

By the way, your solution will probably fail since you must surround date
literals with "#"

=DCount("[Alleged Breach Date]", "[Breach Table]", "[Alleged Breach Date]
#" & Date() - 7 & "#")

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Tom Lake said:
John Spencer said:
The following should work
= DCount("*","[Breach Table]","[Alleged Breach Date]> Date()-7")

Will it know enough to expand the Date() if it's inside the quotes?

Tom Lake
 
H

Hammond-Wandsworth

Thanks chaps, much appreciated. I used John's way and it seems to be working.
Thanks again.

John Spencer said:
Obviously I think so or I wouldn't have posted it that way. And my testing
indicates that it does. ;>)

By the way, your solution will probably fail since you must surround date
literals with "#"

=DCount("[Alleged Breach Date]", "[Breach Table]", "[Alleged Breach Date]
#" & Date() - 7 & "#")

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Tom Lake said:
John Spencer said:
The following should work
= DCount("*","[Breach Table]","[Alleged Breach Date]> Date()-7")

Will it know enough to expand the Date() if it's inside the quotes?

Tom Lake
 

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