Solved Set control value eq to previous record

foshizzle

Registered User.
Local time
Today, 15:03
Joined
Nov 27, 2013
Messages
277
Hello everyone! I have two subforms on one main form. The detail form is a continuous form called 'qryMeterReadingsForm.'
I'm trying to create a textbox control on the header form and set it equal to a prevoius record from the query (or table) that matches whatever is selected in the combobox for the TruckNumber. i.e., the bound MeterStart control should always be the previous MeterStart value for each truck. (Typically this is the previous day).

I thought I would place something like the following in the code but not sure I'm even on the right path here.
=DMax("[Meter1Start]","tblMeterForm","[TruckNumber]= " & [Forms]![frmMeterReadingsHeader]![cboTruckNumber])

I'm attaching a copy of the database here for reference.
Thank you in advance for any assistance.
 

Attachments

Hi. Not sure you have given us enough data in your sample file to do any testing. I only see one record for each truck, so how can I pull the "previous" readings?
 
Touche. Good point. try this one :-)
 

Attachments

That looks correct except Truck93 shows today's entry; the rest are correct though.
 
I was thinking about this, would it be easier to have this work by using the bound control for meterdate; like date - 1? Whichever way is fine with me
 
That looks correct except Truck93 shows today's entry; the rest are correct though.
Okay, I have a question about that. How could today's meter start (36,476) be lower than yesterday's (45,590) for Truck 93?
 
you're right; typo on my part. I spoke with the user and these numbers would only increase; they would never decrease.
 
you're right; typo on my part. I spoke with the user and these numbers would only increase; they would never decrease.
Sounds good. Hope you can manage from here. Good luck!
 
Ok, I found where you wrote the code which makes sense now. Thank you for your help!!!
 

Users who are viewing this thread

Back
Top Bottom