PC Review


Reply
Thread Tools Rate Thread

Count records added in current week

 
 
Tonia King
Guest
Posts: n/a
 
      18th May 2010
I'm trying to work out an expression that will return the number of records
in a table that were added in the current week (Sun-Sat). I have a date
field in the table.

I have tried using a string I found on the forum (below), which was for
quarters, tweaking for weeks, but am new to more complicated expressions and
it returns an error.

=DCount("*","tblRequests","[Date]>=" &
Format(DateSerial(Year(Date()),3*(DatePart("ww",Date())-1)+1,1),"#mm\/dd\/yyyy#"))

Any help most gratefully received.

Tonia

 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      18th May 2010
First day of current week =
DateAdd("d",1-Weekday(Date()),Date())

Last day of current week =
DateAdd("d",7-Weekday(Date()),Date())

DCount("*","tblRequests","[Date]>=" &
Format(DateAdd("d",1-Weekday(Date()),Date()),"#mm\/dd\/yyyy#"))


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Tonia King wrote:
> I'm trying to work out an expression that will return the number of records
> in a table that were added in the current week (Sun-Sat). I have a date
> field in the table.
>
> I have tried using a string I found on the forum (below), which was for
> quarters, tweaking for weeks, but am new to more complicated expressions and
> it returns an error.
>
> =DCount("*","tblRequests","[Date]>=" &
> Format(DateSerial(Year(Date()),3*(DatePart("ww",Date())-1)+1,1),"#mm\/dd\/yyyy#"))
>
> Any help most gratefully received.
>
> Tonia
>

 
Reply With Quote
 
Daniel Pineault
Guest
Posts: n/a
 
      18th May 2010
You could do something along the line of

Function GetRecCount() As Long
On Error GoTo Error_Handler
Dim sSQL As String
Dim rs As Recordset

sSQL = "SELECT Count(tbl_Invoice_General_Info.Inv_Id) AS CountOfInv_Id "
& vbCrLf & _
"FROM tbl_Invoice_General_Info " & vbCrLf & _
"WHERE (((tbl_Invoice_General_Info.Inv_Dt) Between #5/9/2010#
And #5/15/2010#));"

Set rs = CurrentDb.OpenRecordset(sSQL)

If rs.RecordCount > 0 Then
GetRecCount = rs![CountOfInv_Id]
End If

Error_Handler_Exit:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Function

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: GetRecCount" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function

Obviously you need to switch out your Table and Field names. Notice the use
of the Between clause to only pull the count for the date range that you are
interested in.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Tonia King" wrote:

> I'm trying to work out an expression that will return the number of records
> in a table that were added in the current week (Sun-Sat). I have a date
> field in the table.
>
> I have tried using a string I found on the forum (below), which was for
> quarters, tweaking for weeks, but am new to more complicated expressions and
> it returns an error.
>
> =DCount("*","tblRequests","[Date]>=" &
> Format(DateSerial(Year(Date()),3*(DatePart("ww",Date())-1)+1,1),"#mm\/dd\/yyyy#"))
>
> Any help most gratefully received.
>
> Tonia
>

 
Reply With Quote
 
Tonia King
Guest
Posts: n/a
 
      18th May 2010

This is great. Just what I needed. Many thanks

"John Spencer" wrote:

> First day of current week =
> DateAdd("d",1-Weekday(Date()),Date())
>
> Last day of current week =
> DateAdd("d",7-Weekday(Date()),Date())
>
> DCount("*","tblRequests","[Date]>=" &
> Format(DateAdd("d",1-Weekday(Date()),Date()),"#mm\/dd\/yyyy#"))
>
>
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Tonia King wrote:
> > I'm trying to work out an expression that will return the number of records
> > in a table that were added in the current week (Sun-Sat). I have a date
> > field in the table.
> >
> > I have tried using a string I found on the forum (below), which was for
> > quarters, tweaking for weeks, but am new to more complicated expressions and
> > it returns an error.
> >
> > =DCount("*","tblRequests","[Date]>=" &
> > Format(DateSerial(Year(Date()),3*(DatePart("ww",Date())-1)+1,1),"#mm\/dd\/yyyy#"))
> >
> > Any help most gratefully received.
> >
> > Tonia
> >

> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Records for this week, this month, this quarter, this year Silvio Microsoft Access Form Coding 5 14th Dec 2009 10:10 PM
Count Records for this week, this month, this quarter and this yea Silvio Microsoft Access Forms 2 14th Dec 2009 02:51 PM
Count records where date is within the last week pmjb007 Microsoft Excel Worksheet Functions 1 15th Jul 2009 11:41 AM
How to count records w/o counting duplicates by week, month, or ye John Microsoft Access Queries 4 17th Apr 2009 10:28 PM
Formula to determine number of current records by week Keith Microsoft Excel Worksheet Functions 6 6th Feb 2007 04:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:33 PM.