Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access - change start of week to Monday from Sunday (US)

Posted on 2014-09-16
4
Medium Priority
?
40 Views
Last Modified: 2016-06-23
Info you might need: in the US; Access 2010; program someone else wrote; I've only been doing this 6 months.

I'm trying to run queries (and build reports on them) for dates that fall into a "last week" time frame where the week runs Monday to Sunday.

90% of the time, this will be run on a Monday, but I don't want to use Between Date()-7 and Date()-1 because there are times when it might be pulled later in the week. I want the reports to be able to be pulled by clerical people by just pushing a button, not doing anything complicated.

I found this:
   Year([FieldName])* 53 + DatePart("ww", [FieldName]) = Year(Date())* 53 + DatePart("ww", Date()) - 1

And it works like I want, except it returns Sunday to Saturday.

I thought changing my computer settings through control panel to have the week start Monday would help this (changing globally on my computer), but it's still returning Sunday to Saturday.

I've found a couple of things referencing vbMonday for first day of week in specific bits of code (primarily to return a day of the week for a date, but I'm not finding the correct syntax for what I'm looking for. I'd like to set it as a global constant so it covers the whole database.

Can I do this?
0
Comment
Question by:Jennifer Wagner
[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 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 40326083
you  will need a user define function to do this,
place this codes in a regular module

Function GetLastWeekMonDate(CurrentDate) As Date
   If VarType(CurrentDate) <> 7 Then
      GetLastWeekMonDate = Null
   Else
      Select Case Weekday(CurrentDate)
         Case 1       ' Sunday
            GetLastWeekMonDate = CurrentDate - 6
         Case 2       ' Monday
            GetLastWeekMonDate = CurrentDate - 7
         Case 3 To 7  ' Tuesday..Saturday
            GetLastWeekMonDate = CurrentDate - Weekday(CurrentDate) - 5
       End Select
   End If
End Function

Open in new window


in your query, use the criteria

Between  GetLastWeekMonDate(Date) And GetLastWeekMonDate(Date) + 6
0
 

Author Comment

by:Jennifer Wagner
ID: 40326107
Thank you, I'll try it!
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 40327433
I don't know where you found that code but it is far out.

What you need/miss is the weekday parameter used in many VB(A) date functions as in these functions which will fit your purpose:
Public Function DateWeekFirst( _
  ByVal datDate As Date, _
  Optional ByVal lngFirstDayOfWeek As VbDayOfWeek = vbUseSystemDayOfWeek) _
  As Date

' Returns the first date of the week of datDate.
' lngFirstDayOfWeek defines the first weekday of the week.
' 2000-09-07. Cactus Data ApS.
' 2003-05-01. System settings used as default.
' 2012-10-44. Data type of lngFirstDayOfWeek changed to VbDayOfWeek.
    
  DateWeekFirst = DateAdd("d", vbSunday - Weekday(datDate, lngFirstDayOfWeek), datDate)
    
End Function

Public Function DateWeekLast( _
  ByVal datDate As Date, _
  Optional ByVal lngFirstDayOfWeek As Long = vbUseSystemDayOfWeek) _
  As Date

' Returns the last date of the week of datDate.
' lngFirstDayOfWeek defines the first weekday of the week.
' 2000-09-07. Cactus Data ApS.
' 2003-05-01. System settings used as default.
' 2012-10-44. Data type of lngFirstDayOfWeek changed to VbDayOfWeek.
    
  DateWeekLast = DateAdd("d", vbSaturday - Weekday(datDate, lngFirstDayOfWeek), datDate)
    
End Function

Open in new window

Note the use of the VbDayOfWeek enumeration for the second parameter of Weekday. That's the magic that will run weeks from Monday to Monday.

/gustav
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 41668923
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- Gustav Brock (https:#a40327433)
-- Rey Obrero (https:#a40326083)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

MacroShadow
Experts-Exchange Cleanup Volunteer
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

715 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