Results 1 to 7 of 7
  1. #1
    mike_980 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    58

    Query criteria - only show curreny July - July period

    I am looking for some criteria which will only show the current July-July period. For example if the date was today, 28/10/2013 and we ran the query it would fetch results from 1st July 2013 up until 30th June 2014.



    Is there any such criteria

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I was thinking you would need to add the month to something like "SELECT BETWEEN".

    Turns out, adding the month function to your query's criteria should do the trick. You should be able to include your field name within the month function.
    Month([DateField])


    I found this reference on the internet.
    http://www.databasedev.co.uk/retreive_date_query.html

  3. #3
    mike_980 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    58
    would this work though say for example this time next year? as if the date was now thr 28th October 2015, it would need to fetch records from July 1st 2015 up until 30th June 2016? I'm a little unsure on how this function works, i've read the article you posted and it seems to make sense but I'm not sure how i would make it think that July 1st is the first date of the year instead of displaying January - January results?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Try this, to simplify things. In your query, create another field. This field will be a translation of the date field. It will translate a full date value into an integer that represents the month said date falls into. Something like this, in a new field within your query.....

    NewMonthField: Month([NameOfFieldWithDate])

    If you run this in your SELECT query, you will see that you now have a number that represents the month within each date field. Granted, this is not the final result you are after. But, it will help to illustrate how you are now capable of querying multiple records using an integer as criteria, i.e. Where NewMonthField = 7

    Now you can add a year field to your query too.

    NewYearField: Year([NameOfFieldWithDate])

    With this you can create your Where clause within your form's Class Module.


    something like

    Where NewMonthField = 7 AND NewYearField = 12 AND NewYearField = 13

    After you work that out, there may be a way to bypass adding the fields to your query and just associate controls to the SQL directly.

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is one way to do this dynamically (so once you set it up, you do not need to worry about having to updating it at all).

    Create two calculated fields in your query that show the low and high date of the date range based on the current date. Those fields will look like:
    Code:
    LowDate: IIf(Month(Date())>=7,DateSerial(Year(Date()),7,1),DateSerial(Year(Date())-1,7,1))
    Code:
    HighDate: IIf(Month(Date())>=7,DateSerial(Year(Date())+1,6,30),DateSerial(Year(Date()),6,30))
    Now, let's say the name of your date field is "MyDateField".

    In the query, add this criteria under your new "LowDate" calculated field:
    Code:
    <=[MyDateField]
    And add this criteria under the new "HighDate" calculated field:
    Code:
    >=[MyDateField]
    That should then return the records you want!

  6. #6
    mike_980 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    58
    Thankyou! that's exactly what I was after, works perfectly!

    Many thanks!

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome. Glad to help!

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

Similar Threads

  1. Query Help: Averages per user and period
    By Gabriel2012 in forum Access
    Replies: 3
    Last Post: 11-30-2012, 05:46 PM
  2. Query for Specific 24 hour time period
    By esh112288 in forum Queries
    Replies: 1
    Last Post: 10-23-2012, 02:16 PM
  3. Replies: 5
    Last Post: 10-12-2012, 11:00 AM
  4. Replies: 1
    Last Post: 06-12-2011, 07:08 AM
  5. July-June Fiscal Year, Not Jan-Dec
    By blazerboy6 in forum Access
    Replies: 2
    Last Post: 04-14-2011, 02:23 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