Results 1 to 5 of 5
  1. #1
    and13345 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    3

    Comparing a value from two different records in an Access Report

    I have a report that has mileage tracking information in it. I have several fields, one being MT_Odometer_Start and another being MT_Odometer_Finish. What I want to do is compare the MT_Odometer_Start from one record to the MT_Odometer_Finish in another record (the previous record). For instance on 2/2/10 the MT_Odometer_Start value is 22000 and the MT_Odometer_Finish value is 22150, that is one record, the next record on 2/3/10 has MT_Odometer_Start of 22170 and MT_Odometer_Finish of 22200. What I want to do is compare the falue of MT_Odometer_Start in the 2/3/10 record to the MT_Odometer_Finish in the 2/2/10 record. I can't figure out how to make the MT_Odometer_Finish value from the previous record available to the current record. If the value of MT_Odometer_Start in the current record is greater than the value of MT_Odometer_Finish in the previous record I want to display MT_Odometer_Start - MT_Odometer_Finish in the report

    I am using Access 2007.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    and13345 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    3
    Won't that query have a bit of a flaw if there are more than one record for the same vehicle on the same date? In my case I may have two or three entries for the same vehicle on the same day. Say one with ending miles of 22100, one with 22199 and one with 22290. How do I guarantee that the previous one is the right one? I guess if I sort using the VehicleID, then Date then Ending odometer, that should put them in the correct order?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Yes, that should work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    and13345 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    3
    Ok, I was able to modify your query to match my fields and it works, until I have multiple entries for the same vehicle on the same date. I can even get the query in your datebase to produce the same error if I add a second record on the same date for the same carnum.

    The error is this "At most one record can be returned by this subquery."

    If you add the following record to your database you will see the same thing.

    VehicleMiles
    DorDate 5/3/2008
    CarNum 17
    SpeedoEnd 201800

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

Similar Threads

  1. Comparing / Subtracting Tables
    By quigongrim in forum Queries
    Replies: 5
    Last Post: 09-10-2010, 06:59 PM
  2. Comparing two tables with query
    By Dnphm in forum Queries
    Replies: 2
    Last Post: 08-13-2010, 02:45 PM
  3. Comparing fields in Access
    By flames8889 in forum Queries
    Replies: 2
    Last Post: 04-20-2010, 11:55 AM
  4. Help On Comparing Quantity in Tables
    By rochy81 in forum Access
    Replies: 2
    Last Post: 05-29-2009, 10:20 AM
  5. Comparing between fields
    By Dashin in forum Queries
    Replies: 0
    Last Post: 02-13-2009, 08:38 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