Results 1 to 4 of 4
  1. #1
    parabox is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    2

    Last Record from a table

    Hi all, im quite the access noob and I have what is hopefully a simple question to answer for the veterans .




    I've created a database which currently has two tables. One called asset and the other movement. A relationship exists between these tables so that i can find out which movements have been submitted to an asset. (Movement ID is related to the Asset ID in the asset table.)

    My question comes when i try to find the last movement of an asset.

    I have created a query which has a movement id field and a location field. I have set the query totals to group by the movement id field and the location to last.

    This query seems to pull out random records, right now it will only pull the first record or 2nd record if i set the query to first.

    Can anybody help me on this?

    Many Thanks!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    When you say that you want to find the last or most recent movement of an asset that implies that a time is involved. So your query needs to find the maximum date of when the asset was last moved.

    You said that MovementID is the foreign key relating back to the Asset table (and not the primary key of the movement table), so the query would look like this

    SELECT movementID, max(datefield) as MaxOfDateField
    FROM Movement
    GROUP BY movementID

    You would then create a second query (I'll call it Q2) that joins the above query back to the movement table and join by both the movementID fields in both as well as the datefield/maxofdatefield. You would select the fields you want from both souces. Make sure to include the movementID.

    Then you will create a third query that joins the asset table to Q2 via the movementID field.

  3. #3
    parabox is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    2
    So far this work extremely well.

    I really appreciate your help.

    Thanks!!

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

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

Similar Threads

  1. Query w/ 1 record in Table 1, many in Table 2
    By WestofYouLB in forum Access
    Replies: 1
    Last Post: 04-19-2011, 05:02 AM
  2. Insert record from table into different table
    By tpcervelo in forum Forms
    Replies: 3
    Last Post: 01-25-2011, 02:41 PM
  3. Replies: 2
    Last Post: 06-20-2010, 06:54 PM
  4. table name as record
    By stigmatized in forum Access
    Replies: 1
    Last Post: 11-23-2009, 04:34 AM
  5. Move a record from one table to another table.
    By botts121 in forum Programming
    Replies: 4
    Last Post: 06-25-2009, 12:53 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