Results 1 to 2 of 2
  1. #1
    baseball17bucks is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    1

    Select "X number" of most recent records

    Hi,



    I'm pretty new to all of this so please assume I know as little as possible when answering .

    I have been tasked to determine the actual cost to build a product by summing the cost of the most recent required components to come off of our assembly line. For example, say I'm trying to determine the cost of a car with multiple sub-components (1 engine block, 4 doors, 4 wheels, 2 headlights, etc.). We make parts for all kinds of products (cars, boats, televisions, etc.). All of the data for ALL of these parts are contained in a table called PART_DATA (i.e. part ID, date started, date finished, hours spent, etc.).

    Then I have a list of parts required to build a certain model car in a table called CAR_PARTS_LIST. This table contains data like (part ID, quantity needed, etc.).

    If I want to know how much it would cost to build a car using the most recent car-part data, I need to pull data for the most recent required car parts to come off the assembly line that are required for a single car. That is, my car needs 4 wheels, so I need data for the most recent 4 wheels to come off the line.

    How can I write a querey for the "4 most recent wheel records" given that "4" is specified in the CAR_PARTS_LIST?

    Thanks for any help!

    John

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    It's easy to do if you know how many records you want, e.g. 4 - just use TOP n in the query SQL.

    In you case for example, you might have something like:

    Select top 4 field1, field2, ... from Part_Data where criteria ORDER BY [Date Finished] desc

    Criteria is whatever you need to filter for the parts you want. [Date Finished] desc is what you will use to get the 4 most recent records that match the criteria.

    Since it appears that the "4" is variable, i.e. coming from another table, you will probably have to use VBA to define and open the Query.

    HTH

    John

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

Similar Threads

  1. Replies: 1
    Last Post: 12-20-2013, 05:14 PM
  2. Replies: 5
    Last Post: 03-22-2013, 01:11 PM
  3. Replies: 1
    Last Post: 11-27-2012, 02:49 AM
  4. Replies: 1
    Last Post: 10-08-2012, 09:01 AM
  5. File Names in "Open Recent Database" list
    By Ron.Sul in forum Access
    Replies: 3
    Last Post: 12-29-2011, 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