Solved Set control value eq to previous record (1 Viewer)

foshizzle

Registered User.
Local time
Today, 05:28
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

  • Database61.accdb
    548 KB · Views: 102

theDBguy

I’m here to help
Staff member
Local time
Today, 02:28
Joined
Oct 29, 2018
Messages
21,357
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?
 

foshizzle

Registered User.
Local time
Today, 05:28
Joined
Nov 27, 2013
Messages
277
Touche. Good point. try this one :)
 

Attachments

  • Database61.accdb
    688 KB · Views: 97

foshizzle

Registered User.
Local time
Today, 05:28
Joined
Nov 27, 2013
Messages
277
That looks correct except Truck93 shows today's entry; the rest are correct though.
 

foshizzle

Registered User.
Local time
Today, 05:28
Joined
Nov 27, 2013
Messages
277
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:28
Joined
Oct 29, 2018
Messages
21,357
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?
 

foshizzle

Registered User.
Local time
Today, 05:28
Joined
Nov 27, 2013
Messages
277
you're right; typo on my part. I spoke with the user and these numbers would only increase; they would never decrease.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:28
Joined
Oct 29, 2018
Messages
21,357
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!
 

foshizzle

Registered User.
Local time
Today, 05:28
Joined
Nov 27, 2013
Messages
277
Ok, I found where you wrote the code which makes sense now. Thank you for your help!!!
 

Users who are viewing this thread

Top Bottom