Microsoft
Software
Hardware
Network
Question : How do I get correct calculations using Dcount in a Report that is based on a filtered table?
I am using a command button on a form to run a report using 3 to 4 parameters to filter the data. The report has calculated fields that are correct when I use Sum or Count, but erroneous when I use DCount. It appears that the Sum and Count calcualtions honor the filter by the parameters, but the DCount ignores the filter and treats the table as unfiltered.
Here is the code for the report button in the form
Private Sub cmdWeeklyReport_Click()
Dim stCriteria As String
stCriteria = "[Client]= '" & cboClientFilter & "' And DateValue([VisitDate]) Between " & "#" & DateValue(ActXReportStartD
ate) & "#" & " And " & "#" & DateValue(ActXReportEndDat
e) & "#" & ""
DoCmd.OpenReport "WeeklyReport", acViewPreview, , stCriteria
End Sub
Here is the code used in the calculated (counted) field in the report that includes all records in the table instead of the records that are filtered by the criteria listed above.
=DCount("[SiteID]","VisitT
reatmentQu
ery","[Hot
Line] = 'Site visited'")
Here is the code that works correctly:
=Sum([VisitTreatmentQuery]
![TreatAre
aAcre])
Basically, whenever I use Sum or Count, it works. But when I use DCount it uses the entire table and ignores the original filter.
Do I need to repeat the original filter in the criteria in DCount?
If so, what is the syntax for that?
Something like
=DCount("[SiteID]","VisitT
reatmentQu
ery","[Hot
Line] = 'Site visited'") and "[Client]= '" & cboClientFilter & "' And DateValue([VisitDate]) Between " & "#" & DateValue(ActXReportStartD
ate) & "#" & " And " & "#" & DateValue(ActXReportEndDat
e) & "#" & ""
thanks for all the help
Pat
Answer : How do I get correct calculations using Dcount in a Report that is based on a filtered table?
Pat,
Did you try my suggestion of using the open report syntax with the filter argument instead of the where clause (strCriteria) argument?
DoCmd.OpenReport "WeeklyReport", acViewPreview, "YourFilterQuery"
YourFilterQuery is the name of the query that has the additional criteria (the entire revised query, not just the additional criteria)
Random Solutions
DoCmd.TransferText acExportDelim, "", "qryStockExport", file, False, "" not working in an adp
VB me.controls function
trouble with Access buttons
how big can a database be?
Service is not saving the start parameter
How to start / run a stored procedure from a Winform by clicking a button
Odd behavior with C# COM interop and null values
Null Date in Databinder.Eval(Container.<wbr />DataItem, "decom")
Hiding library private members.
Exchange 2010 OWA not working