Current and Past Balances

G

Guest

I am trying to make a query that generates a current balance on a record
using the date of an initial balance and the dates of payments made. This
way I can always make a query to get a balance from the past. So far I have
2 queries that almost do what I want:

Query Name: qryPaymentAmountSum
SELECT Sum(tblPaymentslst.PaymentAmount) AS [Total Paid],
tblPaymentslst.CaseNum
FROM tblPaymentslst
GROUP BY tblPaymentslst.CaseNum;

Query Name: qryCurrentBalance
SELECT tblBalances.CaseNum, tblBalances!InitBal-qryPaymentAmountSum![Total
Paid] AS CurBalqry
FROM qryPaymentAmountSum RIGHT JOIN tblBalances ON
qryPaymentAmountSum.CaseNum = tblBalances.CaseNum
GROUP BY tblBalances.CaseNum, tblBalances!InitBal-qryPaymentAmountSum![Total
Paid];

This almost does what I want except it if the case does not have any
payments the current balance is blank when it should actually be equal to the
initial balance.

If this is not enough to get the idea they please say so.
 
J

jleckrone

When you run your equation in your second query, it evaluates it as
InitBal - NULL and that's why you are getting a Null (blank) result.
Try this in place of your equation:
iif(isNull(TotalPaid), InitBal, InitBal - TotalPaid)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top