Results 1 to 6 of 6
  1. #1
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36

    Current Monday as an anchor in a query

    hello all,

    I am trying to create a function for a SELECT query that uses the current weeks Monday and goes to Sunday. Then the following Monday the records are reset. For example last weeks data is,

    Monday 26 Sep data data data
    Tuesday 27 Sep data data data
    Wed 28 Sep data data data
    Thurs 29 Sep data data data
    Fri 30 Sep data data data
    Sat 1 Oct data data data
    Sun 2 Oct data data data

    The above records are only presented for that date range of that specific week. This week the records should be so far on a Wednesday:

    Monday 3 Oct data data data


    Tuesday 4 Oct data data data

    As you will note, my data is going to be always behind one day of the current day.

    The current Where clause I have is:
    Code:
    WHERE (((SDTicketClosuresforyesterday.Dates) Between (DateAdd("d",-7,Date())) And (Date())));
    This gets 7 days, but it does not do what I describe above.

    I hope I have explained this well enough.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You can use DatePart to get the days of the week (among other things). DatePart(Date()) will be a 4 (Wed), Monday will be a 2, so subtract 2 days from Date() to get Monday's date.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    What are you trying to do in plain English--no Access or SQL jargon?

    Tell us how this fits into your business processes.

    You can use the WeedayName and WeekDay function and the Date intrinsic to get the following:

    ?weekdayname(weekday(date)) & " " & Date
    Wednesday 05-Oct-2016

  4. #4
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    so, an update on this issue. I got really lucky last night and found a function that goes in the where clause that gets all values for the month. I just need to adapt it for the week now.

    Code:
    WHERE  (((DatePart("m",[Dates]))=DatePart("m",DateAdd("m",-1,Date()))) AND  ((DatePart("yyyy",[Dates]))=DatePart("yyyy",DateAdd("m",-1,Date()))));

  5. #5
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    I think I have a winner. I want this where statement to get last week's information.

    Code:
    WHERE (((DatePart("ww",[Dates]))=DatePart("ww",DateAdd("ww",-1,Date())) And (DatePart("ww",[Dates]))=DatePart("ww",DateAdd("ww",-1,Date()))));

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    "ww" is the week number, you want the week day number, which is "w"

    To get Monday's date then:

    IIf(Datepart("w",Date()) > 2, Date() - DatePart("w",Date()) + 2,??)

    10/7 minus 6 (Friday) + 2 (Monday) = 10/3

    Fix the question marks - what do you want to happen if today is a Sunday or a Monday


    (Not sure what "Dates" is, not a very descriptive field name!)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-22-2015, 02:15 PM
  2. Parameter Value = Monday of the current week VBA
    By bcn1988 in forum Programming
    Replies: 4
    Last Post: 09-13-2013, 10:35 AM
  3. Anchor pages in tab control
    By snoopy2003 in forum Programming
    Replies: 2
    Last Post: 03-24-2012, 08:26 AM
  4. Anchor control to bottom of detail section
    By talley in forum Reports
    Replies: 0
    Last Post: 04-04-2011, 10:29 AM
  5. Replies: 1
    Last Post: 07-27-2010, 09:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums