Results 1 to 7 of 7
  1. #1
    rosscortb is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    52

    Help displaying the 6 most recent records

    Hello,



    Hoping you can help please.

    I have trying to display only the 6 most recent records of job title history in a form. If you see the attached, its shows the first job record twice but how do I get it show the second record and so on but capped at 6 the six most recent. Click image for larger version. 

Name:	Capture.PNG 
Views:	25 
Size:	9.8 KB 
ID:	38653

    Hope that makes sense

    If you need more info let me know.

    Thanks
    Ross

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    From W3Schools SQL

    SELECT
    TOP number|percent column_name(s)
    FROM table_name
    WHERE condition;

  3. #3
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    If both of those records are for the same employee id there must be another table involved that's causing the additional records?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Ross,
    Can you show us the code behind the form? Or a copy of the database, so we can see the details.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,130
    Create a query where you sort the required fields by the date field in descending order -newest first.
    Now in the property sheet enter 6 for the Select Top property... Or in SQL view, start with SELECT TOP 6 ...
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    In both records, both start and both end dates are the same - so both records will be in the top 6 group, yes? Yet they may be duplicates.
    Without seeing the employee id, can't tell if one should be removed or not.

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,130
    Sorry forgot about the duplicates part of the question.
    Try starting your query with SELECT DISTINCT TOP 6 to get unique values

    To prevent duplicates in your table, use a composite index on appropriate fields.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Replies: 4
    Last Post: 01-25-2019, 06:28 PM
  2. return most recent records by date stored as text
    By mindbender in forum Queries
    Replies: 3
    Last Post: 04-27-2016, 07:00 AM
  3. Display the most recent Records
    By QA_Compliance_Advisor in forum Queries
    Replies: 5
    Last Post: 08-07-2014, 08:20 AM
  4. Replies: 5
    Last Post: 02-27-2014, 08:25 PM
  5. Displaying Most Recent Record
    By viper in forum Forms
    Replies: 7
    Last Post: 11-16-2010, 10:06 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