Using DCount

Matt_at_Target

Old Dog > New Trick
Local time
Today, 07:32
Joined
Mar 19, 2008
Messages
9
In reading examples of using DCount I am coming away confused. I have a query that gives me the number of days for a location. On the report i want to count how many each location has over 2 so in the Control Source for my report I have the following

=DCount("Narr_Date","Narr_Days","Narr_Date > 2")

I have seen examples where it needed to be coded like this

=DCount("[Narr_Date]","Narr_Days","[Narr_Date] > 2")
and this
=DCount("[Narr_Date]","Narr_Days","[Narr_Date] > '2'")

it seems that I cannot get any of these to work correctly.

What am I missing?
 
Is Narr_Date and numeric data type or a date data type? What does it contain?
 
Data types

Narr_Date is the result of a DateDiff, so I am assuming it is a number

This is the field I am using.

Narr_Date: (DateDiff("d",[case_d],CDate(Left(Mid([si_narr_t],InStr([si_narr_t]," ")+1),InStr(Mid([si_narr_t],InStr([si_narr_t]," ")+1)," ")-1))))
 
Are you running this in the middle of a bunch of other stuff? If so try to see if it works with something simple like a msgbox. Put this behind a button click event:

msgbox DCount("[Narr_Date]","Narr_Days","[Narr_Date] > 2")

???
 
I am using it in a report with about 5 others. The data comes from one query which has about 8 other queries on in it.

I want the field on the report just to count the total for each location if it is greater than 2.

I am trying to run it on the sub query that I have too, just to see if I can get it to work as well.

=DCount("Narr_Date","Narr_Days","Narr_Date > 2") becomes the control source for the TextBox on the report.
 
Shouldn't it be:

=DCount("Narr_Date","Narr_Days","[YourLocationID]=" & Me!YourLocIDField & "Count([Narr_Date]) > 2")
 
I am not sure...

I have about 1200 locations, and I only want the total number of records for each location where the Narr_Date is >2
 
In reading examples of using DCount I am coming away confused. I have a query that gives me the number of days for a location. On the report i want to count how many each location has over 2 so in the Control Source for my report I have the following

=DCount("Narr_Date","Narr_Days","Narr_Date > 2")

I have seen examples where it needed to be coded like this

=DCount("[Narr_Date]","Narr_Days","[Narr_Date] > 2")
and this
=DCount("[Narr_Date]","Narr_Days","[Narr_Date] > '2'")

it seems that I cannot get any of these to work correctly.

What am I missing?
If you just use the DCOUNT statement as the control source for your report you will only pass the the count over to your report. Are you sure that is what you want?
 
I am not sure...

I have about 1200 locations, and I only want the total number of records for each location where the Narr_Date is >2

Sounds like you need a query to get that and then something to display the results of the query, like a subreport.
 
Would I need to change that if I wanted to group that count by location?

The query returns the number of days difference for each location

The query I use to run the report (Admin1), uses this query (Narr_Days) along with others to house all the data I am using.

I use that query in the report. In the report I want to count the total number of records for each location where date difference is greater than 2.
 

Users who are viewing this thread

Back
Top Bottom