Results 1 to 11 of 11
  1. #1
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24

    help to calculate mileages


    hi all

    could anyone help me with a macro or code. what i have is a table for all my vehicle details. i have another table which contains the mileages on the vehicles. what i need to do is when, lets say vehicle A refuels, i need to have the mileage entered into a table. when vehicle A gets refueled again, the mileage needs to be entered again and the previous and current mileage needs to be calculated. this needs to work for all vehicles from A to Z

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I think you will need a table to record details of each refuel.
    You would need the following fields:
    VehicleID field which would have the value of the Primary Key from your vehicle table
    RefuelDate, to record the date when the refuel took place.
    CurrentMileage, to record the mileage reading when the refuel was made.

    Not sure exactly what calculations you want to make but the results should not be saved in a table, better to calculate these whenever and wherever they are required.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    For calculating the miles between fillups, review http://allenbrowne.com/subquery-01.html#AnotherRecord
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    assuming there is a date associated with each refueling (and time if it's refueled more than once a day) you could do something like this:

    James7705.zip

    if you fill up more than once a day you can use the timestamp as well, just bear in mind this is relying on a link that is not the PK so you have to allow for what constitutes a unique record in the absence of the PK

  5. #5
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24
    Hi Bob.
    i already have a table containing VehicleID, RefuelDate, ClosingMileage, FuelQuantity, Driver.
    What I need to do, is have a Report that will calculate the total mileage traveled from last refuel for that vehicle and also calculate the fuel consumption of the vehicle.
    Is this possible?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Did you download the db posted by rpeare?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24
    Hi rpeare

    Yes there will be a date involved, but the office staff will be entering the data received from the fuel slips my technicians bring in. The vehicles fill up about once a week, sometimes more.your sample looks like it could work. i will try it tomorrow and let you know.
    My vehicle table has a lot more fields though... tblVehicles ID; Make; Model; Year; Colour; DatePurchased; Registration; VIN

  8. #8
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24
    Sorry PK? I dont understand that

  9. #9
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24
    Yes I did. Going to try it out at work tomorrow. It looks like it could be exactly what I need

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    PK = Primary Key
    FK = Foreign Key
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    james7705 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2014
    Location
    East London, South Africa
    Posts
    24
    ok

    Thanks to all of you for your help and advice. I have tried the sample posted by rpeare and it will work perfectly for me.

    thanks again

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

Similar Threads

  1. Calculate Interest
    By jgelpi16 in forum Queries
    Replies: 3
    Last Post: 08-19-2016, 08:01 PM
  2. How to calculate a bill
    By Diamond in forum Queries
    Replies: 1
    Last Post: 03-21-2013, 07:17 AM
  3. Calculate Grade
    By DCV0204 in forum Forms
    Replies: 4
    Last Post: 12-13-2011, 02:59 PM
  4. How to calculate?
    By cap.zadi in forum Queries
    Replies: 1
    Last Post: 11-09-2011, 07:29 AM
  5. calculate holidays
    By barkarlo in forum Queries
    Replies: 0
    Last Post: 12-20-2006, 06:08 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