Solved

MS Access Need help with date expression for a report

Posted on 2013-06-13
12
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 52

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 52

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 52

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

628 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