Jun 29 2022 07:36 AM
Experts, I am building an update query.
I need to update tblFXParent to the MAX value of tblFXRollsChild].[DateSettle] where tblFXParent.IDFXParent=tblFXRollsChild.IDParentfk
I am getting an "aggregate function" error as below.
What am I doing wrong?
here is the SQL:
UPDATE tblFXParent INNER JOIN tblFXRollsChild ON tblFXParent.IDFXParent = tblFXRollsChild.IDParentfk SET tblFXParent.DateSettleC = Max([tblFXRollsChild].[DateSettle])
WHERE (([IDFXParent]=[IDParentfk]));
Jul 02 2022 10:01 AM
Jul 03 2022 03:59 AM
Hi Arnel,
Yes, I did see your response. I responded:
Arnel: the update query worked and I compared it to George's output and they matched. I then thought I would have to fire it off many times to keep the data current, by firing an event, but I dont thk that is a "catch all" so some data would be I think "dirty" until I updated, which I think as George alluded to. I think a subquery is what I need since it works in the background without needing an event.
I am not sure how to use that update query inside of a query in the record source. If I did, it seems that could be a workable solution since it would eliminate the need to fire an event.
What are your thoughts?
Jul 04 2022 06:58 AM
Jul 04 2022 07:36 AM - edited Jul 04 2022 07:38 AM
Arnel, as you should know by now, duplicating data and storing calculated values are sub-standard practices in a relational database application.
I admire both your skill with VBA code and your ability to interpret vague requirements and provide logical responses.
In this case, however, continuing to urge a work-around that preserves a sub-standard practice is actually counter-productive to the long-term interests of this poster. It is one thing to use code to implement important functions. That's a really valuable skill and you are very good at it. It is not useful to use that same skill to implement risky work-arounds.
Jul 04 2022 04:09 PM
I have decided to use the update query. I think I have the events covered in the form to ensure it updates when needed (On Open as you mentioned). I also have added it to a report's On Load (I also added it to the form's AfterUpdate). I turned off the warnings and back on too. I will only be using this DMax for a report and will hide the field on the form. I think I am good now. I have tested and it works.
If no objections, I will mark Arnel's as best response since I have ended up using the Dmax function.
thanks for the help guys. I really appreciate it.
Jul 06 2022 04:58 AM
Mar 11 2023 07:49 AM
I have had this same issue prepping data for processing hydrology simulations.
The fix I came up with is to simple create the select query to get your MIN/MAX values, run a Make Table query, then run an Update query from there.
I put all of mine in a macro that creates the tables and then deletes them after the updates are finished.
Not very technical, but it works.