Dsum for the month, but not all years? (1 Viewer)

vidus

Confused User
Local time
Today, 14:16
Joined
Jun 21, 2009
Messages
117
Hey guys,

Having a bit of an issue with this dsum. I used to have this code with a table that contained records for that year only. Now I am combining all years into one table. My dsum code on my form is returning a value for that month as normal but now it includes the month for every year.

For example it will add up june 2010 but also add june 2011.

Ive played around with it a bunch but cant get it to only select the current month AND year... probably really simple but its not coming to me. Below is the dsum:

Code:
=DSum("[Value]","Jobs","Month([Date]) = " & Month([Date]))

Thanks all! :)
 

SOS

Registered Lunatic
Local time
Today, 14:16
Joined
Aug 27, 2008
Messages
3,514
use this instead:

=DSum("[Value]","Jobs","[Date] Between DateSerial(Year(Date()), Month(Date()), 1) And DateSerial(Year(Date()), Month(Date())+1, 0))

That should get you everything for the current month and year.
 

SOS

Registered Lunatic
Local time
Today, 14:16
Joined
Aug 27, 2008
Messages
3,514
(and you should not use DATE as a field name as that is an Access Reserved Word)
 

vidus

Confused User
Local time
Today, 14:16
Joined
Jun 21, 2009
Messages
117
use this instead:

=DSum("[Value]","Jobs","[Date] Between DateSerial(Year(Date()), Month(Date()), 1) And DateSerial(Year(Date()), Month(Date())+1, 0))

That should get you everything for the current month and year.

Thanks I have changed the field to QuoteDate instead. Which "date" specify the field now? I can see why it should not be "date" now...

Is this correct?
Code:
=DSum("[Value]","Jobs","[QuoteDate] Between DateSerial(Year(Date()), Month(Date()), 1) And DateSerial(Year(Date()), Month(Date())+1, 0))

This is giving me an invalid string error.
 

SOS

Registered Lunatic
Local time
Today, 14:16
Joined
Aug 27, 2008
Messages
3,514
Missing a quote:

=DSum("[Value]","Jobs","[QuoteDate] Between DateSerial(Year(Date()), Month(Date()), 1) And DateSerial(Year(Date()), Month(Date())+1, 0)")
 

vidus

Confused User
Local time
Today, 14:16
Joined
Jun 21, 2009
Messages
117
Missing a quote:

=DSum("[Value]","Jobs","[QuoteDate] Between DateSerial(Year(Date()), Month(Date()), 1) And DateSerial(Year(Date()), Month(Date())+1, 0)")

Unfortunately this is returning #Error... I cant figure it out :(
 

Users who are viewing this thread

Top Bottom