Is there any way you could look at the two tables and one form. I will be
send from my police email.
:
It will work. It is a technique I use frequently. I don't know what problem
you are having.
:
I give up it is still not working and I don't think it is going to...Thanks Jen
:
Sorry, I did not check my syntax
=DMax("[EndMiles]", "MilageTable", "[VehicleID] = " &
[Forms]![FrmVehicle]![txtVehicleID]),0)
:
Placed it just like this
=DMax("[EndMiles]", "MileageTable", "[VehicleID] = " &
FrmVehicle.txtVehicleID),0)
but now it gives me a syntac error and will not allow me to use this
expression
:
Actually, I think I gave bad advice, rather than the DLoookup, I think what
you need is DMax, which will return the highest value. The DLookup would
return the first record it finds, which would probably not be the correct
record.
I would suggest you put it in the Control Source property of txtBeginMiles
like this (Note it needs the actual form name here, Me. will not work in this
situation):
=DMax("[EndMiles]", "MilageTable", "[VehicleID] = " & Me.txtVehicleID),0)
:
I double checked and they are listed as numerical but I have been entering
the code under Form AfterUpdate. Is this where I should list it?
:
This is all one line. The _ at the end of the first line is just a line
continuation code. If it fits on one line in your code window, remove it.
Me.txtBeginMiles = Nz(DLookup("[EndMiles]", "MilageTable", "[VehicleID] = " _
& Me.txtVehicleID),0)
Also, this code assumes [VehicleID] is a numeric field in Milage Table. If
it is a text field, you need to enclose Me.txtVehicleID in single quotes like
this:
Me.txtBeginMiles = Nz(DLookup("[EndMiles]", "MilageTable", "[VehicleID] = '" _
& Me.txtVehicleID) & "'",0)
:
I have changed my tables to match what you typed renamed the fields and still
can not get this code to work. It highlights the following as an
error...........HELP
& Me.txtVehicleID),0)
:
I agree with the previous responder, but I do have an alternative to using a
subform to display the previous entries in the milage table. You could look
up the previous ending milagde for the vehiclde in the form's Current event
and put it in the beginning milage control on your form using the DMax
function:
Me.txtBeginMiles = Nz(DLookup("[EndMiles]", "MilageTable", "[VehicleID] = " _
& Me.txtVehicleID),0)
As to having a table for each vehicle - BBBBAAAADDDD IIIIDDDDEEEEAAAA!!!!
:
I track vehicle mileage on all our work vehicles. I have been creating
double entries by entering beginning and ending. How would I create a box to
display the ending mileage from the previous record?
Now my vehicles are sorted by numbers ... unit 12, 21, 22 etc. and how would
I want to create tables to track these? Currently I use one table to track
all vehicles.
Thanks Jen