Results 1 to 15 of 15
  1. #1
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34

    vehicle fuel consuption

    have designed a small access database to monitor fuel consuption. each time we issue a fuel voucher, we record vehicle number plus mileage (meter reading) at start and end and database automatically calculates no of km.

    as of now, users have to enter the meter reading at start and meter reading at end manually using a form.



    what i want is when i choose the car number from my form, then meter reading at start should capture the last meter reading at end (prior to today's entry date) as the default meter reading at start. this will be a locked properties and users will not have input access.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps you could use the DMax() function with criteria to return the mileage.
    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
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Bob, This is what I have been trying (DMax) . Issue is the criteria. Will need criteria to return DMax value where car number on form matches against car number in table AND where entry date on form is less than entry date in table.

    Example, if I were to review a past record, then DMax should be DMax value for the prior date on the from.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps something like:
    =DMax("YourMileageField","TableName","[CarNumberFieldName] = Me.CarNumberControlNameOnForm AND [DateFieldNameInTable] < Date())
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Thank you very much Bob.

    Still not too clear. I am attaching small database whereby you can see the form and table. Grateful if you can us
    Attached Files Attached Files

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Would be please to look at the db but I use A2003 so any thing posted would need to be converted to A2003 mdb format first.
    Alternatively, can you tell us what you're not clear about.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Bob, thanks.

    Formula mentioned by you is :

    =DMax("YourMileageField = Stop","TableName = April 13","[CarNumberFieldName=Car] = Me.CarNumberControlNameOnForm=Car AND [DateFieldNameInTable=Date] < Date())

    converted as

    =DMax("Stop","April 13","[Car] = Me.Car AND [Date] < Date())

    Is that correct?

    Doc10.zip

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    "April 13" seems like an unusual name for a table, but if that is correct it may need to be enclosed in square brackets because it has a space in the name. So, maybe:
    =DMax("Stop","[April 13]","[Car] = Me.Car AND [Date] < Date())
    Also, "Date" is a reserved word in Access so this is poor choice of field name. You may need to change this to something else. Perhaps "RecordedDate". Your expression would then be:
    =DMax("Stop","[April 13]","[Car] = Me.Car AND [RecordedDate] < Date())
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Hi Bob,

    I stil cannot crack this out. I have renamed both the table and date and still not working. It is giving error. I have tried the criteria on both form and in a query but still not getting the correct result. I have checked my criteria over 20 times already and seems ok.

    Can I use an after update or after insert event procedure? I have used a before insert procedure to calculate next ful voucher no and it is working fine. What do u suggest?

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps I could help if you post a copy of the db in A2003 mdb format.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Database10.zip

    Bob,

    Thanks for your help. Really appreciated it. I am attaching copy of DB in A2003.

  12. #12
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Daniel2000

    Sorry for the delay in making a reply.

    Please see the attached db which I THINK will give the result you want but without using the expression we had been looking at.
    I have made changes to the Row Source property of the “Car” combo box and added some code to its After Update property. If this is not what you want or you have questions about how it has been done, please post back.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    I started a milage/fuel usage mdb about 2000. Don't laugh... it was a first attempt.
    I did some updating and converted it to 2010.

    I know it is not what you are trying to do, but it is close. I only save the ending odometer reading and calculate mileage and miles/gal.
    I don't use lookup FIELDS in tables. Unless you are working directly in the table, setting up a lookup field is a waste of time.

    Anyway, maybe this will help......

  14. #14
    Daniel2000 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    34
    Hi Bob,

    Have just checked the database you send. It is doing part of the tasks but not ALL. First thing is that if I entered the wrong car number and goes back to changed it, the startmeterreading keeps showing the stop data from the other car number which was wrongly inserted in the car field. It does not change.

    Secondly, when I entered a new record on the form, it is NOT saving in the April 13 table and thus it keeps showing the MAX startmeterreading from the old records.

    Please check and advise.

  15. #15
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by Daniel2000 View Post
    Hi Bob,

    Have just checked the database you send. It is doing part of the tasks but not ALL. First thing is that if I entered the wrong car number and goes back to changed it, the startmeterreading keeps showing the stop data from the other car number which was wrongly inserted in the car field. It does not change.
    Yes, I see what you mean. Try the attached db.
    Secondly, when I entered a new record on the form, it is NOT saving in the April 13 table and thus it keeps showing the MAX startmeterreading from the old records.
    As far as I can see, the only data NOT being saved is the calculation between the Start and Stop fields (No of km). This is calculated data, so it should NOT be saved, rather calculated whenever and wherever it is required.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. vehicle fuel consuption access database
    By Daniel2000 in forum Programming
    Replies: 3
    Last Post: 08-21-2013, 05:41 AM
  2. fuel consuption database
    By Daniel2000 in forum Programming
    Replies: 6
    Last Post: 08-16-2013, 01:27 AM
  3. Vehicle Mileage
    By Mtyetti2 in forum Forms
    Replies: 5
    Last Post: 02-16-2013, 08:23 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