Hi! I'm trying to implement a prepayment system for my customer orders database. I did this by having an Orders table where I can enter a customer's orders, as well as a Credits table where I can enter a customer's credit payments (a payment of $1000 to be used towards future orders, for example). I have managed to use a Union Query to combine the two into a Transactions query, which shows all orders and credit payments and displays credit payments as positive and orders as negative. This query is sorted by date, from oldest to newest.
For each customer, I need to be able to find out how much prepaid credit he or she has left to use. The way I see this happening is by having the database go down the Transactions query and keep a running total for the customer's remaining prepaid credit. However, I can't just add up all the credit payments and subtract all the orders, since this would ignore the fact that some orders did not come out of a customer's credit and was paid with cash instead (such as if the customer did not have any credit at the time). I think the running total should go something like this:
Sn+1 = max{0, Sn+ x}
where Sn is the running total and x is the next entry in the Transactions query for that customer. This way, if the customer runs out of credit, the running total remains at zero until he adds more credit.
I am relatively new to Access and I'm wondering if this type of calculation is possible. Will I need to use the Expression Builder or another way of doing it?