Solved Dcount function on report (1 Viewer)

unclefink

Registered User.
Local time
Today, 12:57
Joined
May 7, 2012
Messages
184
I've got an existing report that is dependent on an extremely large daisy chain of queries that I built a number of years ago when I was just learning Access and building a new database at that point.

I'm trying to recreate the same report as I need to change the "work week" from what it was when I built the original report to now. Originally Sunday-Saturday now Monday-Sunday.

In any case i've done some digging today and boy am i NOT impressed with the mess i left myself years ago!

The report is comparing a running 3 year comparison "YTD" and i'm trying to just put a text string function in each data field on the report so I can reduce the number of queries if any at all.

I've written some Dcount functions all of which work separately; however when I attempt to put the criteria into one string, i'm getting errors. Can anyone tell me what i'm doing wrong?


Onto the Function: The attempt is to count the number of records in "MainDataTbl" that is between 1/1/2022 a date going back a year based on a date plugged into a Form Field AND the case number starts with BS.


=DCount("*","MainDataTbl","[Casedate] Between DateSerial(Year(Date())-1,1,1)" & "And DateAdd("yyyy",-1,[Forms]![weekqry]![YTDEnd]" & "And [MainDataTbl]![CaseNumber] Like 'BS*'")

When I attempt to run the report, i get an error that says "the expression you entered contains invalid syntax. You may have entered an operand without an operator.

Where have I gone wrong?

PS: This works when I enter dates into the function rather than the date functions so i suspect something is wrong there. Someone please help!
 
You need single quotes around yyyy. The double quotes close off the string.
 
You need single quotes around yyyy. The double quotes close off the string.
Thank you so much for the second pair of eyes and most importantly sharing the wisdom to getting this solved. My Eyes very much appreciate it.
 
Happy to help! I don't like the unnecessary concatenation within the string, but that's personal preference.
 

Users who are viewing this thread

Back
Top Bottom