
Using--After Update-- to update field in table.
Quote:
> UPDATE Customer_Balance_Table
> SET Customer_Balance_Table.AccountBalance
> = TT_Query.SumOfTransactionTotal
> WHERE CustomerID IN
> ( SELECT DISTINCTROW
> Transaction_Table.CustomerID,
> Sum(Transaction_Table.TransactionTotal) AS
> SumOfTransactionTotal
> );
There is a number of problems here:
1) TT_Query.SumOfTransactionTotal refers to a table that does not appear
anywhere else. I think you can use a FROM clause to do updates that need to
happen on joins
2) When you use IN SELECT... you must only return one value: this subSELECT
returns two columns and an unknown number of rows, and there is no FROM
clause.
You might be better served simply by calculating the working balance
(perhaps with a DSUM function) and putting it directly into the UPDATE
command like this:
' get the working balance
dblNewBalance = DSum("TransactionTotal","TTQuery", _
"CustomerID=""" & Me!txtCustID & """")
' Now create the SQL
strSQL = "UPDATE CustomerBalance " & vbCrLf
strSQL = strSQL & "SET AccountBalance = " & _
Format$(dblNewBalance,"0.00") & ";"
' This is really helpful for debugging!
MsgBox strSQL
' Okay, now send it: bracket this with On Error etc.
db.Execute strSQL, dbFailOnError
On the other hand, the fact that this is difficult shows what you lead
yourself into when you ditch relational theory. The AccountBalance is not
dependent on the CustomerID, so it should not be in this table. It's
actually dependent on a number of records in another table, and that is
where it should be coming from.
Your very best plan might be simply to use a query to get the _actual_
account balance when it's needed. But then again, I'm not a banker.
Best wishes
Tim F