AccessFitz said:
Dirk,
I would like to have the recordset updatable. I tried building a
query, but as soon as you establish a relationship between the two,
you can't change any fields.
The Gain/Loss is a calculation within the the text box in the form.
I can build in the SQL if need be. The formual is =((([Trade Date
NAV]-([Corr Date NAV]+[Dist Rate]))*[Shares])). This calculation is
fine. When I change a NAV, the Gain/Loss will change. I just can't
seem to get the Total Gain/Loss to change as well. Remember the
Link# groups the trades together.
The Forms recordsource is a table called Trade Information Table.
The form that I am building is an exact replica of the Trade
Information Table. The specs on the table are Trade Date NAV, Corr
Date NAV, Dist Rate, Shares, Gain/Loss, Total Gain/Loss, and Link #.
Let me know if you need additional information.
It would be nice to compute the grouped sum in the query, and we could
do it that way if you didn't need the form to be updatable.
Unfortunately, once you include any aggregate function in a query, even
in a subquery, the Jet database engine makes the whole query
nonupdatable. So we're stuck with doing it in a controlsource
expression.
You can create a text box for [Total Gain/Loss] and set its
controlsource to this expression:
=DSum("(([Trade Date NAV]-([Corr Date NAV]+[Dist
Rate]))*[Shares])","Trade Information Table","[Link #]=" & [Link #])
Note that the above expression was all entered on one line, though it
will have been broken to multiple lines by the newsreader.
Even with that controlsource expression in place, you'll need to add
code in the AfterUpdate event of the form to recalculate the text box.
It might look like:
Private Sub Form_AfterUpdate()
Me.Recalc
End Sub
You may need a similar line of code for the form's AfterDelConfirm
event. When you change the base values in the current record, the text
box won't reflect the changes until the current record is saved.
Note. by the way, the your table shouldn't have fields for "Gain/Loss"
or "Total Gain/Loss", because these are calculated fields that are
wholly dependent on other fields in the table.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)