JustJerry
01-17-2006, 01:55 PM
Hello everyone,
I am trying to create a database that keeps track of the amount of mileage a vehicle travels in different states.
I have a Main Form frmMainMile with a linked subform subfrmMileDetail. On the form frmMainMile I have two fields that the user enters in the starting mileage and state for a specific month. These fields are [BeginMI] and [BeginST].
Then, on the subform, they will enter in the date, odometer reading, and the name of the state they are crossing into. I also have two other fields, one that calculates the total mileage traveled for the previous state, and one that lists that previous state.
These are the fields of the subform:
[MileDetailID] Unique (Primary Key) ID, autonumbered - hidden from user
[Date] Date that a vehicle crosses stateline
[Mileage] Odometer reading of vehicle at stateline crossing
[State] State vehicle is crossing into
[TotalMileage] Total of miles driven in previous state (Calculated field)
[TotalMileState] Previous State for total miles driven
I am totally confused by how to access the values stored in previous records. But what I do have that works for the FIRST record, is this:
Private Sub Mileage_Exit(Cancel As Integer)
If Me.CurrentRecord = 1 Then
Me.TotalMile.Value = (Me.Mileage - Me.Parent.BeginMI)
Me.TotalMileState.Value = Me.Parent.BeginST
End If
End Sub
After the user exits the field [Mileage], the value for [TotalMile] is calculated from the beginning mileage on the Main Form. Also, the value for [TotalMileState] is entered from the value of the Beginning State on the Main Form.
Now, I want to add an ELSE statement for records 2 and higher of the subform. Basically I need the value of [TotalMile] to equeal the current records value of [Mileage] minus the PREVIOUS records value of [Mileage]and the value of [TotalMileState] to equal the value of the PREVIOUS records value of [State].
Thank you,
Jerry
I am trying to create a database that keeps track of the amount of mileage a vehicle travels in different states.
I have a Main Form frmMainMile with a linked subform subfrmMileDetail. On the form frmMainMile I have two fields that the user enters in the starting mileage and state for a specific month. These fields are [BeginMI] and [BeginST].
Then, on the subform, they will enter in the date, odometer reading, and the name of the state they are crossing into. I also have two other fields, one that calculates the total mileage traveled for the previous state, and one that lists that previous state.
These are the fields of the subform:
[MileDetailID] Unique (Primary Key) ID, autonumbered - hidden from user
[Date] Date that a vehicle crosses stateline
[Mileage] Odometer reading of vehicle at stateline crossing
[State] State vehicle is crossing into
[TotalMileage] Total of miles driven in previous state (Calculated field)
[TotalMileState] Previous State for total miles driven
I am totally confused by how to access the values stored in previous records. But what I do have that works for the FIRST record, is this:
Private Sub Mileage_Exit(Cancel As Integer)
If Me.CurrentRecord = 1 Then
Me.TotalMile.Value = (Me.Mileage - Me.Parent.BeginMI)
Me.TotalMileState.Value = Me.Parent.BeginST
End If
End Sub
After the user exits the field [Mileage], the value for [TotalMile] is calculated from the beginning mileage on the Main Form. Also, the value for [TotalMileState] is entered from the value of the Beginning State on the Main Form.
Now, I want to add an ELSE statement for records 2 and higher of the subform. Basically I need the value of [TotalMile] to equeal the current records value of [Mileage] minus the PREVIOUS records value of [Mileage]and the value of [TotalMileState] to equal the value of the PREVIOUS records value of [State].
Thank you,
Jerry