Solved

MS Access Need help with date expression for a report

Posted on 2013-06-13
12
385 Views
Last Modified: 2013-06-14
I have a table with every day dates:
6-13-13
6-14-13
6-15-13
Etc.

How can I produce a report to display weekly's from the table above? I.E.
Week of June 10
Week of June 17
Week of June 24
Etc.
0
Comment
Question by:DJPr0
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39244709
you will need a function to do that, place this codes in a regular module


Function MondayDate(CurrentDate) As String

   If VarType(CurrentDate) <> 7 Then
      MondayDate = Null
   Else
      Select Case Weekday(CurrentDate)
         Case 1       ' Sunday
            MondayDate = "Week Of " & Format(CurrentDate - 6, "mmm dd")
         Case 2       ' Monday
            MondayDate = "Week Of " & Format(CurrentDate, "mmm dd")
         Case 3 To 7  ' Tuesday..Saturday
            MondayDate = "Week Of " & Format(CurrentDate - Weekday(CurrentDate) + 2, "mmm dd")
       End Select
   End If
End Function



create a query like this

select [dateField], MondayDate([datefield])
from tableName




.
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39244767
Hi,

As Field in a query Field as your Date

MondayDate: "Week of " & Format([Field1]-([Field1] Mod 7)+2,"mmm") & " " & Day([Field1]-([Field1] Mod 7)+2)

Open in new window

like
SELECT Table1.Date, "Week of " & Format([Date]-([Date] Mod 7)+2,"mmm") & " " & Day([Date]-([Date] Mod 7)+2) AS MondayDate
FROM Table1;

Open in new window

Regards
0
 

Author Comment

by:DJPr0
ID: 39244986
Rgonzo1971  One little problem.

Saturdays date will show in the following week: (Mon - Friday dates work fine)

Week of: Jun 17
                                 Dave              Replace Window          6/15/2013

                         

 Week of: Jun 24


Is it possible to display:
Week of: June 2 - June 8
Week of: June 9 - June 15
Etc.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 39245006
did you try the function i posted?

here is the revised function to display  

Week Of: Jun 02 - Jun 08


Function WeekDates(CurrentDate) As String ' Sunday to Saturday range

   If VarType(CurrentDate) <> 7 Then
      WeekDates = Null
   Else
      Select Case Weekday(CurrentDate)
         Case 1      ' Sunday or Saturday
            WeekDates = "Week Of: " & Format(CurrentDate, "mmm dd") & " - " & Format(CurrentDate + 6, "mmm dd")
         Case 2 To 6       ' Monday.. Friday
            WeekDates = "Week Of: " & Format(CurrentDate - Weekday(CurrentDate) + 1, "mmm dd") & " - " & Format(CurrentDate - Weekday(CurrentDate) + 7, "mmm dd")
         Case 7  ' Saturday
            WeekDates = "Week Of: " & Format(CurrentDate - Weekday(CurrentDate) + 1, "mmm dd") & " - " & Format(CurrentDate, "mmm dd")
       End Select
   End If
End Function
0
 

Author Comment

by:DJPr0
ID: 39245300
capricorn1 - I created the module.

Do I need to create a separate query to supply the report?

Not sure where I place the query below.


select [dateField], WeeklyDate([datefield])
from tableName
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39245316
<Do I need to create a separate query to supply the report? >

what is the record source of your report ?

if it is a query,  post the SQL statement of the query.

if it is a table, you need to create a query and change the Record Source of the report.

after you created the query, post the SQL statement of the query.

so we can correct it if needed.



.
0
 

Author Comment

by:DJPr0
ID: 39245374
Here is my select statement for my new query:

SELECT tblDates.RefDate, WeekDates([datefield])
FROM tblDates;


I receive an error: Undefined function "Weekdates" in expression.

The Weekdates module is in my list of modules.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39245558
what name did you give to your module?


use this query


SELECT tblDates.RefDate, WeekDates([RefDate])
FROM tblDates;
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39245937
Hi,

Sorry, I forgot the weekend

MondayDate: "Week of " & Format([Field1]-(([Field1]-2) Mod 7),"mmm") & " " & Day([Field1]-(([Field1]-2) Mod 7))

Open in new window

Regards
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 39246202
This would be ideal for a PivotTable, grouped by week.  Unless you are using Access 2013, where PivotTables have been dropped.
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 39246653
Hi,

a simplfied version of my code
MondayDate: "Week of " & Format([Field1]-(([Field1]-2) Mod 7),"mmm dd")

Open in new window

Regards
0
 

Author Closing Comment

by:DJPr0
ID: 39248497
Thanks experts, both solutions worked!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question