Is there a better way to find most recent?

revver

Active Member
Joined
Dec 20, 2007
Messages
257
I have a form/subform based on two related tables (1-many) in the usual way. The subform has a date field.

For a given record in the main form I want to find the (date of the) most recent detail record. My first thought is to create a RecordSet of qualifying detail records ordered by date descending. The first record in this RecordSet will be the one I want.

Now I think there is probably a better way than using a RecordSet. Any ideas?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Thank you but my question is not about who changed data. I already use a technique described by Allen Browne for that.

My question is:
I have tblVehicles and tblServiced in a 1-many relationship. I want to find the most recent date that Vehicle_123 was serviced. This I can do by creating a RecordSet which contains all the records in tblServiced for Vehicle_123 and sorting that RecordSet in date order.

Is there an easier way?
 
Upvote 0
A recordset is probably the way to go if you want to move to that record. If you just want to know which record it is, you could use a listbox on the main form whose rowsource is a Top 1 query of the subform, filtered to the correct vehicle and sorted descending on date.
Don't forget to requery the listbox when you switch records on the main form.

Denis
 
Upvote 0
Thanks Denis.

All I really want is the date.

I was debating whether to add a field to the main table and updating it each time a new service record is added.

The trouble has been that service records dated earlier than the most recent one have been trickling through and upsetting the apple cart. I would need to test the date to see if this service record should update the main table or not.

So I still haven't decided whether to add the field or not.
 
Upvote 0
You could do the following:

1. In the subform, in Design view, add a textbox called txtLatest to the form's Footer. Make the Control Source an expression like
=Max([ServiceDate])
...or, use DMax if Max doesn't work.
2. In the main form, place a textbox. Its control source should be
=[The name of the container for the subform].Form![txtLatest]

You can find the container's name (it doesn't always match the name of the subform) by clicking the subform ONCE in design view, then looking at the Property sheet.

Denis
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top