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
Pass Web Page as Parameter to Class in App_Code Folder
video card driver
Problem with "like" keyword, when database is in chinese
active directory, W2k8 R2 DC, Kerberos failures, Event ID: 3, 4771, 4769, 4768, 4776, 4625 source: Microsoft Windows security
Access attaching a file as xls when it should be rtf
RUNDLL error message "jyku.fjo" on computer start up
Same form on different computers
Textboxes in other Tabs in asp.net
XP display set to 4 bit color depth after Remote Desktop session
Error when assigning value to textbox in footer during runtime