Solved

MS Access Need help with date expression for a report

Posted on 2013-06-13
12
356 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 119

Expert Comment

by:Rey Obrero
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 48

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
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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 119

Expert Comment

by:Rey Obrero
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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 119

Expert Comment

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


use this query


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

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 48

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

17 Experts available now in Live!

Get 1:1 Help Now