Hi, I am trying to Sum a field with criteria and can't get one query to do this.
These two will do the job.
This selects the Records.
And this Sums the first.
Is there a way to combine these two (maybe subquery) so that it is just one string ?
I want to then use this sql string in a VBA Function to get the Sum result.
This will replace:
The sql will hopefully get me up to a value that I can then subtract "GetRecordSums("RepayMentsAll") to arrive at the final result.
Appreciate any advice.
These two will do the job.
This selects the Records.
PHP:
SELECT TBLTRANS.TRNACTDTE, TBLTRANS.TRNTYP, TBLTRANS.TRNDR
FROM TBLTRANS
WHERE (((TBLTRANS.TRNACTDTE)<=Date()) AND ((TBLTRANS.TRNTYP)="Interest")) OR (((TBLTRANS.TRNTYP)="Late fee")) OR (((TBLTRANS.TRNTYP)="Legal Fees"));
And this Sums the first.
PHP:
SELECT Sum(QueryTesta.TRNDR) AS SumOfTRNDR
FROM QueryTesta;
Is there a way to combine these two (maybe subquery) so that it is just one string ?
I want to then use this sql string in a VBA Function to get the Sum result.
This will replace:
PHP:
Public Function FunctionCurrentBalanceAllSum()
Dim SumOverDue As Currency
'Sum Late fee, Legal Fees, Interest from TBLTRANS
SumOverDue = DSum("TRNDR", "TBLTRANS", "TRNACTDTE<=Date() AND TRNTYP In('Interest', 'Late fee', 'Legal Fees')")
'Sum Principal from TBLTRANS & Add to SumOverDue
SumOverDue = SumOverDue + DSum("TRNPR", "TBLTRANS", "TRNACTDTE<=Date() AND TRNTYP In('Interest')")
'Sum PaymentsAmt from tblMemberRepayments and subtract to SumOverDue
SumOverDue = SumOverDue - GetRecordSums("RepaymentsAll")
'Give Result of SumOverDue to Function CurrentBalanceAllSum
FunctionCurrentBalanceAllSum = SumOverDue
End Function
The sql will hopefully get me up to a value that I can then subtract "GetRecordSums("RepayMentsAll") to arrive at the final result.
Appreciate any advice.
