Results 1 to 6 of 6
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Date Range Picker

    I want to understand how to create this common date picker.

    Normally I see this in Combo boxes in many databases.

    2020/2021
    2021/2022
    2022/2023


    and so on.

    These dates are generally 1st April to 31st March

    1. How would I construct this?
    2. How could I have it auto create a new range ie, when its near to 2023/2024 year range?
    3. Could I use this to filter queries from a user defined form?


    Regards

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In a form put 2 text boxes: txtStartDate, txtEndDate
    you can set default dates for them.

    the query would use:
    select *from table where [datefld] between forms!fMyForm!txtStartDate and forms!fMyForm!txtEmdDate

    you can add a combo to set the date span by picking a year.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    If I had to do exactly what you are asking, I'd probably do it this way
    Create a table that holds start and end date per range
    Create the visible combo that shows Year(StartDate) & "/" Year(EndDate) and the start and end dates as extra columns.
    Then when you select an entry, you use those other columns as criteria.

    This also allows you to specify other dates, not always 1st April and 31st March.

    If that was always the case, then you could just get by with a year column, and create the other values on the fly.?, but I think that would be risky.
    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

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    you can create a range in a query to use as your recordsource. Assuming your range is always a year

    1. create a table, populate it with 1 to 99 in a field called num. This will give you 100 periods. Use more or less numbers as required
    2. in a query use this something like this syntax

    Code:
    SELECT 2000+[num] & "/" & 2000+[num]+1 AS Period, DateSerial(2000+[num],4,1) AS FromDate, DateSerial(2000+[num]+1,3,31) AS ToDate
    FROM numTable
    WHERE (2000+[num])<=Year(Date())
    ORDER BY [num]
    change 2000 to when you want your list to start, modify the WHERE clause where you want it to finish and change the dateserial values for different month/days as required

    In your combo, have 3 columns and hide the last two

    In a query reference the combo columns 1 and 2

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    In a query reference the combo columns 1 and 2
    As criteria? I thought combo columns were not accessible by queries.

    EDIT - A claim I have seen posted here more than once, and prior attempts to do so always raised an error.
    However, I just found that it is possible!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Steven19 View Post
    These dates are generally 1st April to 31st March...
    Quote Originally Posted by Welshgasman View Post
    If I had to do exactly what you are asking, I'd probably do it this way
    Create a table that holds start and end date per range
    Create the visible combo that shows Year(StartDate) & "/" Year(EndDate) and the start and end dates as extra columns.
    Then when you select an entry, you use those other columns as criteria.

    This also allows you to specify other dates, not always 1st April and 31st March.

    If that was always the case, then you could just get by with a year column, and create the other values on the fly.?, but I think that would be risky.
    Sounds like you need the flexibility to change the range? I like Welsh's plan for a date table.

    I might consider instead of storing a [beginning of period] and [end of period] date/time maybe only storing a [beginning of period] date/time and in your queries filter *something* like this
    Code:
    WHERE some_date >= [beginning of period]
      AND some_date < [beginning of NEXT period]
    Note that dates in access are stored as floating point numbers. That filter, I think, should prevent inadvertently excluding records in your queries... maybe it's not necessary. I'll hang up and listen

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

Similar Threads

  1. Replies: 13
    Last Post: 04-09-2020, 07:22 AM
  2. Replies: 17
    Last Post: 07-31-2018, 01:23 PM
  3. Replies: 3
    Last Post: 01-26-2016, 01:56 PM
  4. Replies: 11
    Last Post: 06-28-2015, 06:42 PM
  5. Show Date Picker on Load and Verifying Date
    By Markb384 in forum Forms
    Replies: 4
    Last Post: 03-04-2014, 07:44 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