Solved

MS Access Need help with date expression for a report

Posted on 2013-06-13
12
376 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 49

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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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 49

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 49

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Can I Grab This Information off a PDF Form 23 46
word 2016 1 29
Delete QueryDef IF it Exists: Access VBA 5 28
Binding recordsets to a form 6 21
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now