Results 1 to 15 of 15
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Exclude years in front from query

    I have as a criteria which I assume is showing the bookings for this year and 2 years back using the criteria below.

    Between Year(Now()) And Year(Now())-2



    Click image for larger version. 

Name:	Capture.JPG 
Views:	22 
Size:	21.5 KB 
ID:	13778

    however I would like the query to exclude any bookings above the current year....

    any suggestions?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What do you mean by 'above the current year' - 2014 and on? I don't see the query capturing 2014 and on.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    after, anything after the current year. So if year is 2013 then 2014, if year is 2014 then 2015 and nothing in 2015 can show.

    BookingDate is the date field.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Still don't understand. The parameters shown should not capture any future years. However, I would put the earlier parameter first just because it's easier to visualize the construct, although either should work:

    Between Year(Date())-2 And Year(Date())
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Still don't understand. The parameters shown should not capture any future years. However, I would put the earlier parameter first just because it's easier to visualize the construct, although either should work:

    Between Year(Date())-2 And Year(Date())
    For some reason if I don't format BookingDate into year first then Between Year(Date())-2 And Year(Date()) won't work as a where

    so I had to make calc: year([tblBookings]![BookingDate]) first then use Between Year(Date())-2 And Year(Date())

    That gives me the same results as before - it lists the schools with bookings within those dates (2012, 2013) but doesn't exclude the schools with bookings that are in 2014...

    Click image for larger version. 

Name:	Capture.jpg 
Views:	18 
Size:	120.8 KB 
ID:	13784

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I guess what I am saying is yes it is only showing the results of that school from between this date and this date but it isn't excluding the school that has dates after that period.

    so ideally a criteria would be

    between this date and this date

    AND

    no school id with a date after this date

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I don't know why that would be the case. Only records meeting all 3 criteria should display.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    I don't know why that would be the case. Only records meeting all 3 criteria should display.
    yes that is correct only those do. However there are schools with bookings that have dates after the dates that are displayed - so even though I am showing the schools with bookings within that date period I am not excluding any schools that have bookings after that date period because they happen to have dates in the within date (and thus displayed).

    The idea is that I want to show schools that have had bookings for this year however as soon as they get a booking for next year as well then they are automatically removed from the list by query.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Okay, means criteria based on data in other records of same table. That is tricky.

    A subquery or DLookup might work.

    Calculate another field in the query with:

    DLookup("BookingDate","tblBookings","Year([BookingDate])>Year(Date()) And NewSchoolsID=" & [NewSchoolsID])

    Then criteria under that constructed field: Is Null
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Okay, means criteria based on data in other records of same table. That is tricky.

    A subquery or DLookup might work.

    Calculate another field in the query with:

    DLookup("BookingDate","tblBookings","Year([BookingDate])>Year(Date()) And NewSchoolsID=" & [NewSchoolsID])

    Then criteria under that constructed field: Is Null
    I honestly thought of using a subform but I figured it could be replicated on a continuous form. I will give your dlookup suggestion a try as I would prefer that.

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Ruegen View Post
    I honestly thought of using a subform but I figured it could be replicated on a continuous form. I will give your dlookup suggestion a try as I would prefer that.
    It works with where instead of group in the query but because there are so many records it does take some time to load.... might limit to those that have over 5 bookings or something.

    Thanks June7

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, domain aggregate functions can slow down queries. Might be able to use subquery, like:

    SELECT * FROM tablename WHERE NewSchoolsID Not In (SELECT NewSchoolsID FROM tablename WHERE Year(BookingDate)>Year(Date));

    However, I don't have much experience with the In/Not In operators, not sure if you can have other filter criteria along with it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Sorry June I have to go back to this one.

    I had to delete NewSchoolsID from tblBookings (which used to work with the above dlookup) because that is unused and not an updated field. The formula relied on it.

    Is there another way around? I tried pulling only the NewSchoolsID from tblTeacher and left out the table for the schools, then placed as a where in the BookingDate <#1/1/2014# just to test anything before that date would be excluded but for some strange reason in the grouped query the schools with bookings (BookingDate) above 1/1/2014 are still showing.

    I can't use the dlookup because that field is missing and it can't find tblteacher!newschoolsID for some reason.

    updated query
    Click image for larger version. 

Name:	Capture.JPG 
Views:	8 
Size:	72.8 KB 
ID:	14128

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, this has gotten stale for me and I can't even recall what led me to the previous suggestions. I would have to start over from scratch and don't know when I will be able to. Even if I do try, don't think I know enough about your db.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Sorry, this has gotten stale for me and I can't even recall what led me to the previous suggestions. I would have to start over from scratch and don't know when I will be able to. Even if I do try, don't think I know enough about your db.

    all good I will try fresh start

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

Similar Threads

  1. Replies: 2
    Last Post: 07-31-2013, 11:16 PM
  2. Replies: 1
    Last Post: 09-06-2012, 01:40 PM
  3. Query to exclude non matching records
    By L1882 in forum Queries
    Replies: 1
    Last Post: 04-03-2012, 08:44 AM
  4. exclude field in query
    By chrisy in forum Queries
    Replies: 2
    Last Post: 10-28-2011, 09:53 AM
  5. Replies: 4
    Last Post: 10-25-2011, 10:07 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