Results 1 to 15 of 15
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Search by year


    I'm trying to make a search by using only a year. I have several records with many different dates. I want to only see those in a certain year. I want every record in that year. I want to only use the four digit year instead of inputting a beginning and ending date.

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are the dates stored in time/date field?

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Yes. Dates are stored in the table as Date/Time

  4. #4
    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 is the Date field you intend to query??

    ...where Year (yourDatefield) = 9999

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Sorry Orange, I didn't quite understand. I'm trying to query the date that is on the record. It's a regular short date field. There are many records with different dates and years. I want to be able to look at all the records with the year I need to search. Example, if I want to see everything from 1/1/2016 - 12/31/2016, I want to be able to search for 2016 and get everything.

  6. #6
    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

  7. #7
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Hate to say this, but it looks like SQL. I'm not very good with SQL. Can I write it into the query criteria?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Or....

    You didn't state the field name. So in the following change "yourDatefield" to your actual field name.

    In the query add a new column-> OnlyYear:Year (yourDatefield)
    In the Criteria row, enter-> 2016
    Run the query.....

  9. #9
    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

  10. #10
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Oops ssanfu. The field name is OpenDate

  11. #11
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That worked great. Thanks. Having one more issue. I have a form I use to enter what I'm looking for. When I enter this into the criteria, it stops working:
    [Forms]![frmSearchIAComplaintClass]![Year]. I'm trying to have it look for whatever year I enter into the text field YEAR.

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Shouldn't use "Year" as an object name. "Year" is a reserved word and a build in function.

    When I enter this into the criteria, it stops working:
    Explain "stops working". Is there an error message?


    Can you attach the dB? With maybe 10 - 20 records for testing purposes?
    Do a "Compact & Repair", then Zip it.

  13. #13
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Thanks again. I had forgotten about the reserved words. No error messages. I changed the name to txtYrSearch. Still the same results though. The query just comes up blank. I'll post some pictures.

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    There was something wrong with my search form. I redid it from scratch. It works like a charm. I appreciate the help. Thanks.

  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Glad you got it sorted out......

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

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2017, 01:09 PM
  2. Replies: 1
    Last Post: 10-14-2015, 03:45 PM
  3. Replies: 3
    Last Post: 06-22-2015, 06:36 AM
  4. Replies: 1
    Last Post: 11-01-2013, 11:53 AM
  5. search records by month and year
    By nurul in forum Forms
    Replies: 8
    Last Post: 12-09-2012, 09:34 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