Results 1 to 5 of 5
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    163

    Filter for records where Field = True, but also the record before that.

    Shown below is a very simple table. I want to write a Query that does two things:
    1) Filter by "Condition Met" = True ... no problem.
    2) Also shows the record before! I have no idea how to do this.



    For clarity, applying those rules to the table below would yield records with ID#'s 3, 6, and 10 because of the checkmarked/true condition, and also somehow return records immediately preceeding them with ID#'s 2, 5, and 9 in the same result set.

    Thank you for any input.

    Click image for larger version. 

Name:	Untitled.png 
Views:	9 
Size:	9.6 KB 
ID:	19952

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    when Query1 is in design view; in the 'Criteria' row under the ConditionMet field you put: -1

  3. #3
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    163
    For the first goal of the query, that's correct, that's the easy part. But the second part of the query seems impossibly difficult: include the previous record as well. I'm guessing some sort of nested query, or possibly even vba programming? no idea.

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    the correct implementation depends upon the data integrity. If the next record preceding it is always a prior date or a prior ID then:

    Using ID field as example:

    join Query1(described previously) to the table joining the 2 ID fields

    then you must put the query into SQL View and manually modify the join syntax from 'ID=ID' to be 'ID=ID AND Table.ID = Query1.ID-1'
    this isn't the exact syntax as you must include the table name but hopefully you get the jist
    you won't be able to view this query in design view once you do that
    this is advanced

  5. #5
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    163
    Wow, I can't believe it actually worked lol. Yes it took a little bit of playing but I got it (as it happens the "AND" you mentioned should be "OR"), and it felt good to see it accomplished. Thank you so much, Matt.

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

Similar Threads

  1. Replies: 9
    Last Post: 12-09-2014, 09:02 AM
  2. Replies: 7
    Last Post: 04-10-2014, 02:22 PM
  3. Replies: 4
    Last Post: 03-08-2014, 05:24 PM
  4. Replies: 4
    Last Post: 02-03-2014, 12:16 PM
  5. Replies: 12
    Last Post: 02-10-2013, 10:13 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