Duplicate sub form last record

T

TinMan

Hi all i have a sub form with a numeric field what i am hoping for is when
someone opens the main form and navigates to a new record in a sub form is it
possible to lookup last record and duplicate the field.

The sub form is to record the amount of fuel used, the cost and date. It
also holds the start mileage and end mileage. I would like the finish mileage
to be entered automatically as the start mileage on a new record entry. Many
Thanks to all who help others
 
S

Stefan Hoffmann

hi,
The sub form is to record the amount of fuel used, the cost and date. It
also holds the start mileage and end mileage. I would like the finish mileage
to be entered automatically as the start mileage on a new record entry. Many
Use the forms Before Insert event with the appropriate field names:

Private Sub Form_BeforeInsert(Cancel As Integer)

If IsNull(Me![finishMileage]) Then
Me![finishMileage] = Me![startMileage]
End If

End Sub



mfG
--> stefan <--
 
D

Dale Fye

Set the StartMileage textboxes control source to:

=NZ(DMAX("End_Mileage", "YourTable"), 0)

My guess is that your main form will have a vehicle ID or something like
that. If that is the case, they you will have to modify this to something
like:

=NZ(DMAX("End_Mileage", "YourTable", "VehicleID = " & me.parent.VehicleID), 0)

Which will find the maximum value for "End Mileage" for the particular
vehicle that is displayed in the main form.
 
T

TinMan

Hi there Dale, I don't need the max finish mileage just the last entry of
finish mileage to be entered automatically into new record start mileage.
Thanx for helping me!!
 
T

TinMan

Hi Stephan, I tried this but nothing happens. Can you suggest anything else.
Cheers for your help

Stefan Hoffmann said:
hi,
The sub form is to record the amount of fuel used, the cost and date. It
also holds the start mileage and end mileage. I would like the finish mileage
to be entered automatically as the start mileage on a new record entry. Many
Use the forms Before Insert event with the appropriate field names:

Private Sub Form_BeforeInsert(Cancel As Integer)

If IsNull(Me![finishMileage]) Then
Me![finishMileage] = Me![startMileage]
End If

End Sub



mfG
--> stefan <--
.
 
T

TinMan

Hi there Dale, I do have a relationship set up by [RegNo] between Parent &
Sub, though i don't need DMax just value of last record to duplicate
automatically. Any ideas many thanks

Tom
 
T

TinMan

TinMan said:
Hi there Dale, I don't need the max finish mileage just the last entry of
finish mileage to be entered automatically into new record start mileage. Have Used

=NZ("End_Mileage", "FuelUseage", "Reg = " & Me.[Vehicle Details].Reg), 0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dynamic Naming of Form Button 3
Split form 0
Copy previous record into form field 0
CALCULATION 5
Mail Merge Help 1
CALCULATIONS 1
Duplicate record in Form and Subform 0
Need some PWA help 0

Top