Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So from the 1st of month to 3rd week, it is Date()+1, then from there to end of month (or the first of next, whichever way you want to look at), it is MonthEnd()+1?

    Where do you want to start counting weeks? August 2015 first week has only 1 day. First full week starts Aug 2 (Sunday as first day of week). So which of those should be week 1?

    There is no intrinsic function for returning the week number of the month, so determining what the '3rd week' is won't be easy.



    Easiest would be to make a cutoff date of like the 15th of each month.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Yes, I wondered about that situation.

    Can you use weekday then? 1st weekday and 3rd week weekday?

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Weekday returns the day number within the week. Still doesn't identify which week of the month. No indication if it is 1st or 3rd.

    As noted, what one calls the 'first' week is subjective.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Actually it's not, it's the full week. Since a week consists of 7 days. It's the # of the week in the month.
    1st day is obviously, it's day one of the month

    "
    week
    wēk/
    noun
    noun: week; plural noun: weeks
    a period of seven days.
    "the course lasts sixteen weeks"

    the period of seven days generally reckoned from and to midnight on Saturday night."

    https://en.wikipedia.org/wiki/Week

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I have seen posters with some odd requirements for what would be the month start and end.


    Test the Weekday function in the VBA immediate window.

    ?Weekday(#8/24/2015#)

    returns 2

    ?Weekday(#8/31/2015#)

    also returns 2

    So don't know what you mean by "It's the # of the week in the month".
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    I currently have these functions:
    Code:
    Function MonthStart()
        MonthStart = DateValue(Month(Date) & "/1/" & Year(Date))
        Select Case Weekday(MonthStart)
        Case 1
            MonthStart = MonthStart + 1
        Case 7
            MonthStart = MonthStart + 2
        End Select
    End Function
    
    Function MonthEnd()
        MonthEnd = DateAdd("m", 1, (Month(Date) & "/1/" & Year(Date))) - 1
    End Function
    
    Function PrevMonthStart()
        PrevMonthStart = DateSerial(Year(Date), Month(Date) - 1, 1)
    End Function
    
    Function WeekStart()
        WeekStart = Date - (Weekday(Date) - 2)
        If Date - (Weekday(Date) - 2) = 0 Then WeekStart = WeekStart - 7
    End Function
    
    Function Yesterday()
        Yesterday = Date - 1
        Select Case Weekday(Yesterday)
        Case 1
            Yesterday = Yesterday - 2
        End Select
    End Function
    
    Function WorkDay(tmpDate As Date) As Boolean
    If Weekday(tmpDate) = 1 Or Weekday(tmpDate) = 7 Then WorkDay = False Else WorkDay = True
    End Function
    I was thinking something like
    Code:
    =Iif(Date() >= MonthStart(), >=Date()+1, if(it's the start of the 3rd week of the month, then >=MonthEnd()+1)
    So something for identifying if today is the start of the 3rd week of the month and incorporating correctly in the if statement?

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That last expression would be the criteria in query?

    The >= operator cannot be part of the IfTrue and IfFalse arguments.

    >= IIf(Date() >= MonthStart(), Date(), MonthStart()) + 1
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #23
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Quote Originally Posted by June7 View Post
    That last expression would be the criteria in query?

    The >= operator cannot be part of the IfTrue and IfFalse arguments.

    >= IIf(Date() >= MonthStart(), Date(), MonthStart()) + 1
    Odd, this is producing all dates from today

    However if I cannot use >=, it won't work anyway.

  9. #24
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can use >=, just can't be in the argument. It must be in the criteria like:

    SELECT * FROM table WHERE [somefield] >= IIf(Date() >= MonthStart(), Date(), MonthStart()) + 1;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #25
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    That, for the [ShippingDate] produced all orders with shipping dates from now until the end of the date in the db.

    it should only be until the end of the month right now.
    then at the beginning of the month it should only show one day out from Date()

  11. #26
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Then you need a date range criteria.

    SELECT * FROM table WHERE [somefield] BETWEEN IIf(Date() >= MonthStart(), Date(), MonthStart()) + 1 AND {another IIf to select the end date};
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #27
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Quote Originally Posted by June7 View Post
    Then you need a date range criteria.

    SELECT * FROM table WHERE [somefield] BETWEEN IIf(Date() >= MonthStart(), Date(), MonthStart()) + 1 AND {another IIf to select the end date};
    The start of the BETWEEN statement could work. how do you add in the later, where it has to say IF it's the beginning of the 3rd week?
    I can forgo the 3rd weekday. that really isn't that important.

    So from the 1st through the end of the 2nd full week it should be >=Date()+1, remainder of the month, beginning of the 3rd week, needs to be >=MonthEnd()+1

  13. #28
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I have no idea how to determine what the week number of the month is. Never had to do this.

    So I did Bing search: Access VBA week number of month

    http://bytes.com/topic/access/answer...er-given-month
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2015, 04:15 PM
  2. Replies: 3
    Last Post: 10-22-2014, 02:38 AM
  3. Replies: 2
    Last Post: 07-15-2014, 12:00 PM
  4. Dynamic Date Range?
    By aellistechsupport in forum Programming
    Replies: 7
    Last Post: 04-29-2014, 09:25 AM
  5. Replies: 1
    Last Post: 05-25-2011, 08:37 AM

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