Need to find a previous record (1 Viewer)

Mark6455

New member
Local time
Today, 05:47
Joined
May 30, 2021
Messages
1
I have an Access database for tracking costs and other data of my truck. One such record is when my engine goes into a regeneration mode. What I need to do is find the last record entered for a regen, then subtract the mileage from the PREVIOUS regeneration so as to get the miles between regenerations.

Regeneration data is stored in a record called "Regeneration"
Mileage is stored as "Start Mileage" and "End Mileage"

To summarize, I need the current regeneration mileage minus the previous regeneration mileage and list the number.
If I regened at 20,210 and the previous mileage Regen was 19,810, I need to show the difference which is 400 miles.

I don't know how to figure the previous number in a query.

Thanks in advance
 

G37Sam

Registered User.
Local time
Today, 13:47
Joined
Apr 23, 2008
Messages
454
You need an ID field in your Regen table - Using DAO: open that table in ascending order of that ID, scroll to the last record and then goto the previous record.

Another way is to use DMAX(RegenID,tblRegen) -1 but you'll have to make sure the ReGen ID increments 1 at a time using the BeforeInsert Event
 

jdraw

Super Moderator
Staff member
Local time
Today, 05:47
Joined
Jan 23, 2006
Messages
15,379
Might be helpful to you and readers if you showed your table design(s).
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:47
Joined
Feb 19, 2002
Messages
43,266
You can just find the max mileage for the truck since mileage always stays the same or goes up.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:47
Joined
May 7, 2009
Messages
19,241
you can use DMax() function.
your Last Mileage:

dblLastMileage = DMax("[End Mileage]", "Regeneration")

dblDifference = CurrentMileageReading - dblLastMileage
 

Users who are viewing this thread

Top Bottom