Dcount since last sunday (1 Viewer)

Leyton01

Registered User.
Local time
Tomorrow, 05:23
Joined
Jan 10, 2018
Messages
80
I am trying to get a running total of documents we process during the week, displayed in an unbound text box with a dcount as the value.

I have managed to get the daily count using:
=DCount("*","[tblDocumentLog]","Int([DateCreated])= #" & Date() & "#")

But I am struggling with the correct syntax to count all documents that have been created since the last Sunday.

I am using Australian dates (so same as UK) and the database is never used on a Sunday, so the count on Sunday does not have to be correct (ie doen't matter if it is a single day count or 7 days count).

Bonus round: total since the first of the month.

Thanks!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:23
Joined
Aug 30, 2003
Messages
36,125
Last Sunday:

?date() - Weekday(date(), 1) + 1
8/26/2018

First day of the month:

?DateSerial(Year(date()), Month(date()), 1)
8/1/2018
 

Minty

AWF VIP
Local time
Today, 20:23
Joined
Jul 26, 2013
Messages
10,371
This returns the Monday of the current date

Code:
Date()- Weekday(Date(), vbMonday) + 1
So
Code:
=DCount("*","[tblDocumentLog]","Int([DateCreated])>= #" & Format( Date()- Weekday(Date(), vbMonday) + 1, "yyyy-mm-dd") & "#")

Should do the trick For part one.

Code:
Dateserial(year(date()), month(date()),1)

Returns the beginning of the current month. I'll let you have a play :)

Edit - Damn that Baldy's faster typing skills....
 

Leyton01

Registered User.
Local time
Tomorrow, 05:23
Joined
Jan 10, 2018
Messages
80
Thank you both for your help - a combination worked.


It errored out with vbMonday so had to use "1", also it did not like Format in the weekly expression:


Code:
DCount("*","[tblDocumentLog]","Int([DateCreated])>= #" & (Date()-Weekday(Date(),1)+1) & "#")
Opposite to this, the monthly would only work with the format code??
Code:
DCount("*","[tblDocumentLog]","Int([DateCreated])>= #" & Format(DateSerial(Year(Date()),Month(Date()),1),'yyyy-mm-dd') & "#")
Cheers
 

Users who are viewing this thread

Top Bottom