Results 1 to 8 of 8
  1. #1
    SamL is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2021
    Location
    NJ
    Posts
    20

    Display Top X, and move X backwards from there

    The users requested that I give them the ability to display the last 10 records they entered, and permit changes to them. Using the Top 10 clause, I gave them that ability, but now they're requesting I allow them to see additional screens of 10 records, sequentially backwards from the original.

    Example: There theoretically can be 150 records with the user's initials. They view the first screen, which displays backwards, say, from October 30th to October 15th, 2021. They want the ability to view the next screen of 10, showing, say, from where it left off to, say, October 2nd. And so on.



    I can't figure it out. How do I do this?

    Thanks,
    Sam

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You could MoveLast in the form RecordsetClone and get the date (LastDate variable). Of course, the order of the displayed records matters.
    Then alter the recordsource query for the form to be Top 10 WHERE dteSomeDate < LastDate if that fits with your current Top 10 clause. That part I'm not sure of because I don't know if they're viewing the records in ascending or descending date order after you have presented them. It could even be that you need to MoveFirst because of that.
    Last edited by Micron; 11-14-2021 at 08:48 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    perhaps along these lines

    first group - select top 10 * from table order by ID desc
    second group - select top 10 * from table where ID NOT IN (select top 10 ID from table order by ID desc) order by ID desc
    third group - select top 10 * from table where ID NOT IN (select top 20 ID from table order by ID desc) order by ID desc
    fourth group - select top 10 * from table where ID NOT IN (select top 30 ID from table order by ID desc) order by ID desc
    etc

  4. #4
    SamL is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2021
    Location
    NJ
    Posts
    20
    Thanks to both of you. I understood Ajax's fix just a bit better, because the ID# is really the operative field here, but there could be many entries on a single date, while missing other dates. If I understand correctly, you're both essentially saying the same thing. And yes, I am displaying the records in descending order. I've got some work to do.

    It's after midnight in New Jersey, and I gotta get to bed. See ya manyana.

    Thanks again,
    Sam

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Dates seemed to be the driver here so that's what I went with. You can have
    ID | ADate
    11 | 10/23/2021
    12 | 09/20/2021

    Which one is the latest record? No need to answer, just elaborating on the reason for using date. If the ID approach works for you by all means make use of one of Ajax's many excellent solutions.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    don't disagree with date - so I would sort by date, then ID

    if records are
    1..1st Dec 21
    2..1st Nov 21
    3..1st Nov 21

    and your query does not include the ID and is just TOP 1 sorted on date asc will return 2 records. Include the ID and you will just get the one record but the question is 'which one will you get?' it will be random so the next time you run it it may return the other record without a sort on ID as well.

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    SamL,

    Just saw this thread. In overview, you have a number of Users who are processing some records. These records are each identified as being the responsibility of User X or Y..etc (initials). You want to select records(grouping) by UserResponsible and by DateOfRecord descending to get them in proper sequence (your displays backwards).
    A few questions to get details:
    You identify which records should retrieved and processed by user (initials)?
    How do you identify a record that has been edited/completed or whatever the user does when retrieving his/her records?
    Suppose in one session user X selects 10 records that are tagged as user X's responsibility. X processes 6 records, then gets called away. X returns later--- does X select the last 10 unprocessed, or the second 10 records (records 11-20)? I expect the former.
    Last edited by orange; 11-15-2021 at 11:20 AM. Reason: clarification

  8. #8
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    In a continuous form's module, I create a constant:
    Code:
    Option Compare Database
    Option Explicit
    
    Const cstrSQL As String = "SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP $n * FROM Table ORDER BY ID DESC)  ORDER BY ID ASC)  ORDER BY ID DESC;"
    With a unbound combobox in form's header named cboPage, as page selector, with a value list 1,2,3... etc, I choose the page (or the group of last ten records):
    Code:
    Private Sub cboPage_AfterUpdate()
        Me.RecordSource = Replace(cstrSQL, "$n", Me.cboPage * 10)
    End Sub
    I think it's working.

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2016, 07:45 AM
  2. Move record out and display It in another form ?
    By Lukael in forum Programming
    Replies: 5
    Last Post: 01-06-2016, 07:07 AM
  3. Replies: 3
    Last Post: 12-03-2014, 01:40 PM
  4. I think I put the keys backwards in my database design.
    By Melaniecarr23 in forum Database Design
    Replies: 1
    Last Post: 03-11-2014, 09:15 PM
  5. Forms Populating Backwards
    By kbrown in forum Forms
    Replies: 0
    Last Post: 06-21-2011, 09:47 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