SELECT
(SELECT
IIF(IsNull(sum(b.AmountCharged) - sum(b.AmountPaid)),
a.Balance,
(sum(b.AmountCharged) - sum(b.AmountPaid)))
FROM tblCurrentTransaction AS b
WHERE b.TenantTransactionID <= a.TenantTransactionID
AND b.Tenant = a.Tenant
GROUP BY b.Tenant
) AS TrueBalance, a.TenantTransactionID
FROM tblCurrentTransaction AS a
ORDER BY a.Tenant, a.TenantTransactionID;
UNION
UPDATE tblCurrentTransaction SET tblCurrentTransaction.Balance = TrueBalance
WHERE tblCurrentTransaction.TenantTransactionID = a.TenantTransactionID;
Basically what happens is I get a result set from the first query, then I match it's TenantTransactionID with the update query. However Access complains: "An action query cannot be used as a row source"
How can I fix this?
This is the query without the UNION
UPDATE tblCurrentTransaction SET tblCurrentTransaction.Balance = (SELECT
(SELECT
IIF(IsNull(sum(b.AmountCharged) - sum(b.AmountPaid)),
a.Balance,
(sum(b.AmountCharged) - sum(b.AmountPaid)))
FROM tblCurrentTransaction AS b
WHERE b.TenantTransactionID <= a.TenantTransactionID
AND b.Tenant = a.Tenant
GROUP BY b.Tenant
) AS TrueBalance
FROM tblCurrentTransaction AS a
WHERE a.TenantTransactionID = tblCurrentTransaction.TenantTransactionID
ORDER BY a.Tenant, a.TenantTransactionID;
);
But it doesn't do anything, and Access complains "Operation must use an updateable query"
This is the query that gathers the data This query returns the true balance, and the transaction ID it belongs to. This is what I need to insert into the table.
SELECT (SELECT IIF(IsNull(sum(b.AmountCharged) - sum(b.AmountPaid)),a.Balance, (sum(b.AmountCharged) - sum(b.AmountPaid)))
FROM tblCurrentTransaction AS b
WHERE b.TenantTransactionID <= a.TenantTransactionID AND b.Tenant = a.Tenant
GROUP BY b.Tenant
) AS TrueBalance, a.TenantTransactionID
FROM tblCurrentTransaction AS a
ORDER BY a.Tenant, a.TenantTransactionID;