Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40
  1. #31
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    I use an option group. It's designed to do what your apparently doing with code.

    Here's another version. In this one I use a function to return a string of either this weeks or next weeks dates which is the row source of the combo box.
    I also included a listbox as another option.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  2. #32
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Moke123, thank you, i did read through the code of your suggestion, i am going to download and go have a look, i have more time today to do this so happy days, as always, greatly appreciate all of your suggestions

  3. #33
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The part that determines the weekday start of the week is in red below:

    Code:
    SELECT NumTable.N, DateAdd("d",[n]-Weekday(Date()),Date()) AS ThisWeek, DateAdd("d",[n]+7-Weekday(Date()),Date()) AS NextWeek, WeekdayName(n,0,1) as DoW
    FROM
     (SELECT 
        DISTINCT Abs([id] Mod 10) AS N
    FROM 
        MSysObjects)  AS NumTable WHERE (((NumTable.N)>0 And (NumTable.N)<8))
    The details of which are here : https://learn.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/weekdayname-function
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #34
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,990
    @moke123
    When I run that, I get Tuesday to Saturday as the 9th is being a Thursday?
    I have now amended that code with vbMonday.

    Also I get the dates in mm/dd/yyyy format?, yet my system is dd/mm/yyyy, as I am in the UK?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #35
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    Quote Originally Posted by Welshgasman View Post
    @moke123
    When I run that, I get Tuesday to Saturday as the 9th is being a Thursday?
    I have now amended that code with vbMonday.

    Also I get the dates in mm/dd/yyyy format?, yet my system is dd/mm/yyyy, as I am in the UK?
    I'm a Yank so I code in American.

    You can change this line to format the dates
    Code:
           strItem = Format(dte, "mm/dd/yyyy") & "  " & WeekdayName(Weekday(dte), True)
    Not sure why you get tuesday to saturday other than perhaps you have different settings.

    Click image for larger version. 

Name:	cbxdave.jpg 
Views:	17 
Size:	29.4 KB 
ID:	50628
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #36
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,990
    Quote Originally Posted by moke123 View Post
    I'm a Yank so I code in American.

    You can change this line to format the dates
    Code:
           strItem = Format(dte, "mm/dd/yyyy") & "  " & WeekdayName(Weekday(dte), True)
    Not sure why you get tuesday to saturday other than perhaps you have different settings.

    Click image for larger version. 

Name:	cbxdave.jpg 
Views:	17 
Size:	29.4 KB 
ID:	50628
    Damn!
    Sorry, never noticed that despite adding vbMonday.

    Getting so used to having to format that way for SQL etc.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #37
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks guy's i have come back to this now, going to check out Moke123 Option Group method, Minty's version of qryNext2Weeks works well, but will look at option group

    Thanks again

  8. #38
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,990
    Quote Originally Posted by DMT Dave View Post
    Yes, no changes to Mintys code on my side and get the 8th as wed today and 15th for next week

    I am curious about NumTable where Minty has added to a table that doesn't exist, never seen that before, i always thought you need a source table, interesting

    I also like Moke123 version

    Minty's version is perfect for me also because once the dates are set correct, when i choose optThisWeek then delivery date is Combo Column(1), when optNExtWeek is selected then delivery date is Column(2)

    i have tried changing the criteria numbers in N field but getting incorrect dates as you see

    This qry also will be correct 365 without updating is by the looks of it

    1st and last line didn't make sense, changed values in N field then left it how Minty wrote it!!!
    Are you sure you have not mucked about with his code?

    As this
    Code:
    WeekdayName(n,0,1) as DoW
    determines the day shown?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #39
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi WGM, yes added that in, for some reason the query wouldn't save the changes but i have had numerous internet/server/telephone issues today for some reason so going to try again, had 3 restarts!! so i am unsure if that were the case

    I will delete the query and start a new one with this added from SQL before saving

  10. #40
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,990
    Just copy and paste the latest version.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Get Date Of This Week Based On Day Name
    By DMT Dave in forum Access
    Replies: 22
    Last Post: 02-02-2023, 12:15 AM
  2. Replies: 3
    Last Post: 08-27-2020, 09:27 AM
  3. Replies: 9
    Last Post: 06-19-2015, 03:37 PM
  4. Replies: 3
    Last Post: 01-21-2015, 02:40 PM
  5. Finding last week
    By jgelpi16 in forum Queries
    Replies: 5
    Last Post: 09-21-2010, 02:32 PM

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