Results 1 to 5 of 5
  1. #1
    mark6455 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    3

    Lookup specific data in a table


    I have a database for vehicle history and expenses. Within that database is a place for regeneration (of a diesel engine). The name of that source is "Regeneration". Since this function does not always occur, I need to extract certain data from time to time.

    What I need to do is search the database for "Regeneration", note the "Date" for that, then subtract the most recent Regeneration "Start Mileage" from the prior Regeneration "Ending Mileage".

    There are over 84 Regenerations that have occurred to date. So the end result should look like this:

    Date: September 1, 2021
    Start Mileage: 58,000
    Ending Mileage: 58,020
    Regen Length(in miles) 20

    Any guidance appreciated!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    I know what diesel regen is (was a class A truck/coach and automotive mechanic for about 25 years) so maybe I can help. You've shown the desired result but what's missing is what your data looks like. Also, I see nothing in the result that indicates which engine/vehicle this is for, so that's important too. If you really want to shorten this, post a db with some sample data. Alternatively, you could copy/paste & post (you should get a table here). A spreadsheet(s) as an attachment would be good, but a db would be best.

    Worst case scenario, you might need a subquery.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,679
    What you mean with <The name of that source is "Regeneration">? You have a table named Regeneration in your DB? What about other types of maintenance - do you have a separate table of every one of them (You did say it is a 'database for vehicle history and expenses'!)?

    I'd have a table for vehicles - like:
    tblVehicles: VehicleID, VehicleProducerID, VehicleModel, VehicleProduced, ...;
    A table where you register vehicle owner(s) - like:
    tblVehicleOwners: VehicleOwnerID, VehicleID, OwnerID, OwnedAtDate;
    ...
    A table where you register all vehicle maintenance operations:
    tblVehicleMaintenance: VehicleMaintenanceID, VehicleID, MaintenanceDate, MaintenanceType, MaintenanceCost, ...
    A table where you register all possible maintenance types - like:
    tblMaintenanceTypes: MaintenanceTypeID, MaintenanceTypeDescription (one of types will be with description like 'Engine Regeneration')

    So when you need to get the info e.g. about last engine regeneration for certain vehicle, you have to query the table tblVehicleMaintenance for VehicleMaintenanceID with latest MaintenanceDate for given VehicleID and MaintenanceType (e.g. using a subquery which returns TOP 1 records for those VahicleID and MaintenanceType, ordered by MaintenanceDate descending), and then return the info from tblVehicleMaintenance with this VehicleMaintenanceID. Probably the best way to do this is to write an UDF (or several - an UDF for every value like date, cost, etc. to be returned) for this - with VehicleID and MaintenanceType as parameters.

  4. #4
    mark6455 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    3
    Thanks for replying. Due to my work schedule, it will take me a day or two to get a DB posted. Labor Day weekend is a big O.T. few days for me. On my way out now.

  5. #5
    mark6455 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    3
    I gave "regen" its own category. Other maintenance is (other than fuel) is listed elsewhere and the invoice for maintenance is scanned in to the database.

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

Similar Threads

  1. Replies: 3
    Last Post: 06-15-2019, 08:51 AM
  2. Replies: 9
    Last Post: 08-11-2016, 11:30 AM
  3. Replies: 1
    Last Post: 09-21-2015, 02:25 PM
  4. Replies: 1
    Last Post: 05-31-2015, 09:20 AM
  5. Using lookup data for table 1 mutible times in table 2
    By mbjazz in forum Database Design
    Replies: 5
    Last Post: 04-26-2011, 01:18 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