Results 1 to 5 of 5
  1. #1
    HeyMoe is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2023
    Posts
    8

    Find Year in a Range Of Years

    I'm trying to develop a database to catalogue LPs/CDs.


    One thing I would like to do is to specify which decade a LP was released.

    So I would have a simple table with
    Decade/StartYear/EndYear.
    60's /1960 /1969
    70's /1970 /1979
    etc. You get the gist.

    In the main table, there would be a column with release date in a Month/Year format. eg. June-1975
    I would like to then create a query that would look up the decade based on this release date.
    Would this be difficult to do?

    Thanks.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No. Pretty simple really.
    I would use a DlookUp() with the value from the YEAR() function on your date. Use Between StartYear and EndYear as the criteria.
    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

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I would have a field for the month and a field for the year. They can be concatenated in forms/reports if you wish.
    I would like to then create a query that would look up the decade based on this release date.
    It is usually best to perform a calculation whenever and wherever it is required, rather than saving it to a field in a table. A calculation like this would usually be done n the query used as the Record Source of the form/report.
    Just as a matter of interest, how will you distinguish between say, the 1920's and the 2020's ?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    HeyMoe is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2023
    Posts
    8
    Quote Originally Posted by Welshgasman View Post
    No. Pretty simple really.
    I would use a DlookUp() with the value from the YEAR() function on your date. Use Between StartYear and EndYear as the criteria.

    Thanks Welshgasman.
    Correct me if I'm wrong, but DlookUp() is a function used in VBA.
    How would you do this using only SQL? (If it's possible of course.)

    Cheers.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by HeyMoe View Post
    Thanks Welshgasman.
    Correct me if I'm wrong, but DlookUp() is a function used in VBA.
    How would you do this using only SQL? (If it's possible of course.)

    Cheers.
    To use a query join, I believe you would need a record for each year?

    60's 1960
    60's 1961

    etc

    You can use DLookUp in a query, but not recommended for large datasets.
    I doubt your record collection comes into that category?
    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

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

Similar Threads

  1. Replies: 17
    Last Post: 07-31-2018, 01:23 PM
  2. Filter a report by a Year Range using a form
    By Chapster5 in forum Forms
    Replies: 3
    Last Post: 10-05-2016, 09:09 AM
  3. Replies: 12
    Last Post: 08-10-2014, 12:54 PM
  4. Replies: 2
    Last Post: 05-20-2014, 02:28 PM
  5. Crosstab query with date range (2 years)
    By Cassim in forum Queries
    Replies: 7
    Last Post: 11-11-2013, 08:48 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