Dcount records by date

dark11984

Registered User.
Local time
Today, 10:51
Joined
Mar 3, 2008
Messages
129
Can someone give me a hand with this one... Not sure where my speech marks should be?

Code:
=DCount("[id]","[qrysso]","[Month]=" & Month(DateAdd("m",-1,Date())) And "[Year]=" & Year(DateAdd("m",-1,Date())))

Cheers
 
Try

=DCount("[id]","[qrysso]","[Month]=" & Month(DateAdd("m",-1,Date())) & " And [Year]=" & Year(DateAdd("m",-1,Date())))
 
No good... get #Error message
 
What are the data types of the month and year fields? Those aren't good names by the way, as Access will confuse them with the functions of the same name.
 
ok i've changed the names of the fields. They are formatted date fields from a query - SSOMonth: Format([SSODate],"mmm") and SSOYear: Format([SSOYear],"yyyy")
 
The month field is returning text so the DCount() syntax will need to be adjusted as noted here:

http://www.mvps.org/access/general/gen0018.htm

Probably the same for the year field. Even though it's returning a numeric looking value, the Format() function will return a string value.
 
Thanks, I've been looking for a link like that to explain the apostrophes however, ive tried a few different variations and am winding up with either #error or 0 as the result.

Code:
=DCount("[id]","[qrysso]","[ssoyear]= '" & Year(DateAdd("m",-1,Date())) & "' And [ssomonth]= '" & Month(DateAdd("m",-1,Date())) & "'")
 
I think you have a mismatch between these two:

SSOMonth: Format([SSODate],"mmm") which will produce "Sep"

Month(DateAdd("m",-1,Date())) which will produce 9

You need to compare "apples to apples".
 
Now that makes sense... Got it working. I changed the format in my query to "mm" and here's the code I finished up with.

Code:
=DCount("[id]","[qrysso]","[ssoyear]= " & Year(DateAdd("m",-1,Date())) & " And [ssomonth]= " & Month(DateAdd("m",-1,Date())))

Thanks for your help!
 
No problem, glad we got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom