Query for latest record based on date field

number1pita

Board Regular
Joined
Oct 8, 2013
Messages
51
Hello,

The database (non Access) we have didn't gain historical perspective that we could report from, so we are data dumping into an Access database. I am trying to build a query where it will update a field in a table (field "Exempt" in tblSeptemberRR) based off the most recent entry in another table (field "Risk Exempt" based of field "Last Updated" date in tblEngagement).

Would someone be able to help me in figuring out how to do this? I tried to create a select table where it would include all the unique identifiers, the field Risk Exempt from tblEngagement and then tried Max of Last Updated, but when I view it, it shows both dates for the unique identifier, not the most recent.

Any help would be greatly appreciated.

Thanks!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this, but first back up the table (save a copy) to be affected.
Create a query "qryREforMaxDate" that gets the Risk Exempt value based on the maximum date, assuming that is what you mean by most recent entry. Dump this sql into the query sql view window, run it, and confirm it is the correct value by looking at your table:
Code:
SELECT [tblEngagement].[Risk Exempt] FROM [tblEngagement] 
WHERE ((([tblEngagement].[Last Updated])=(SELECT Max([tblEngagement].[Last Updated]) AS 
MaxOfDate_Submitted FROM [tblEngagement])));
Then create a query in the same manner to update the target table:
Code:
UPDATE [tblSeptemberRR], [qryREforMaxDate] 
SET [tblSeptemberRR].[Exempt] = [qryREforMaxDate].[Risk Exempt];
If you choose to view this in datasheet view before actually running it, it should show you how many rows will be updated. Note, you may see values, or empty rows depending on whether or not anything is already there. What you are looking at is not the impending result - it is just the number of records that will be affected.
Hopefully, I have kept your table/field names straight in my head! If it does not work and you cannot figure out why, be sure to post what you created and any error numbers with error message text. Something as simple as a missing space between two words can cause this to fail.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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