Hello Richard, I'm a big fan of your Access videos. I'm trying to help a friend who owns a small business. I'm struggling to find a solution after scouring the web and hoping you can help. In Access I have a customer form and a transactions subform for tracking AR transactions for when we bill customers for services, charge things to their account and take payments. I'd like the subform to show a list of transactions that map to the current customer record (including transaction date, transaction type & amount) as well as the updated account balance resulting from each transaction. The last thing needed is the current balance for the current customer record. The subform is based on an aggregate query using a DSUM formula. I can't figure out how to filter this so that only the current customer's transactions and balances are displayed. Any help would be appreciated.
Thanks, Kyle.
Adam Schwanz
@Reply 2 years ago
If you go to the property sheet under Data, are Link Master Fields and Link Child Fields set? That would be the easiest.
Or you could change the record source of the subform to include the where condition.
Select * From CustomerT Where CustomerID=Forms!CustomerF!CustomerID
Kyle RappOP
@Reply 2 years ago
Hi Adam, yes I do have the subform property sheet configured to map CustomerID on the Customer record to CustomerID on the Transaction record, which is also how the one-to-many table relationship is set between Customers and Transactions.
What's happening is the list of transactions are correctly filtered, but the running total (balance) is counting all transactions, not just those for the currently-selected customer.
Adam Schwanz
@Reply 2 years ago
Oh, you need to change the criteria on your balance field then, There's a few ways you could setup the running balance criteria, I'm not sure what you have now, but it may need to be something like this
DSUM("Balance","Table","CustomerID=" & CustomerID & " and InvoiceNumber<" & InvoiceNumber)
Kyle RappOP
@Reply 2 years ago
Hi Adam, basically what I have now is a Customer table and a Transactions Table. One-to-many relationship with a CustomerID field on both tables. The customer form has basic customer info. The transactions table has the list of transactions and a form to enter input or change transactions. Then I have a subform to show a list of transactions on the customer record. The subform is based on a query. The transaction table has an "amount" field which is the field I'm trying to sum up. That said, the Customer record does not have a balance field. The only balance field I have is one I created on the query which queries the transactions table and uses a DSUM. Would it help if I paste in the SQL statement? Thanks again.
Kyle RappOP
@Reply 2 years ago
Basically, I want to sum up all transactions for whichever customer record I am on, but the running total needs to reflect the date of a transaction, so that I can see how each transaction impacted the balance. thanks again and I'm sorry if I'm not doing a good job explaining this. I would visualize it as how you can look through online banking and see every transaction, in order and what the new balance is as a result of each transaction. Its working like that now except that its also counting transactions for other customers even though the subform is only displaying transactions for the correct customer.
Adam Schwanz
@Reply 2 years ago
Adam Schwanz
@Reply 2 years ago
See if this helps you, the bottom control source is for the running balance field.
Kyle RappOP
@Reply 2 years ago
ok so in your example the running balance is just calculated on the form, vs. a query? Is that where I am mixed up? Again I really appreciate the help.
Adam Schwanz
@Reply 2 years ago
Yes, you could probably put that into the query as well if you wanted, same way, just make a new line like RunningBal: Format(DSUM(.... rest of the code
Kyle RappOP
@Reply 2 years ago
ok, so I will remove it from the form and add it to the query instead. The subform is based on the query and so I will make sure to include the RunningBal query field on the subform. Thanks Adam. Will let you know how it turns out. I've been trying to figure this out for days LOL.
Kyle RappOP
@Reply 2 years ago
Unfortunately still no luck. No matter what I do, the subform is still wrong. While it does list only transactions for the current customer on the customer form, the balance listed next to each transaction reflects transactions that are for other customers. In otherwards, its displaying the correct transactions and transaction amounts but the running balance is the total for all customers. Again any help is appreciated. Thanks, Kyle
Kevin Yip
@Reply 2 years ago
Hi Kyle, a subform's can only have a single SQL statement as its record source, and it may be tough to get running balances into a subform in the manner you described with just a single SQL statement. So you may need to use other methods.
A temporary table may help. Store the customer's line items into a temporary table that has a blank column for storing running balances later. Then use a recordset loop in VBA to go through line by line, calculate the running balance for each line, and save them into the table. You will have a much easier time calculating running balances that way, because you'll have VBA variables and functions at your disposal. If you need to find the opening balance for any customer at any starting date, you can do it with VBA as well. When that's done, you just use the temporary table as the subform's recordsource.
Kyle RappOP
@Reply 2 years ago
Hi Kevin, thanks for your reply. So, one thing I would like to clarify is that its not like an order with multiple lines. Each transaction is simply a payment or a charge towards a customer's account. When we invoice them it increases their payable balance. When they make a payment it decreases their payable balance. Each transaction has a dollar amount, date, TransactionID, Description, and CustomerID. So, I don't need to add up line items to arrive at an order total. I only need to add up all the charges and payments, for the customer, including this transaction and the previous ones. The Transactions subform correctly displays only the transactions for the user shown on the Cusrtomer form (the parent form). The only issue is that the total next to each transaction includes transaction amounts from all customers instead of only the transactions showing on the subform for the selected customer. I don't understand why it only shows Kyle's transactions but shows totals for ebveryone's transactions, even though I am mapping the CustomerID of the transaction record to the CustomerID of the Customer record.
Kyle RappOP
@Reply 2 years ago
Kyle RappOP
@Reply 2 years ago
Kyle RappOP
@Reply 2 years ago
So, in the first screenshot (the query) you can see all transactions for all customers. The balance of $8910 on the highlighted line for a transaction for Kyle reflects a charge of $2910 which is for John on the line below.
If you look at the second screenshot, you can see it correctly shows only Kyle's transactions in the subform but it still sums all balances for all customers vs only the ones listed on the subform.
Kyle RappOP
@Reply 2 years ago
Hello all, I was able to find a solution that works. Here is the SQL view of the query that the subform is based on:
<CODE>SELECT T1.CustomerID, T1.TransactionDate, T1.TransactionID, T1.TransactionType, T1.[PaymentMethod], T1.TransactionDetails, T1.TransactionNotes, T1.TransactionAmount, T1.BalanceAdjustment, SUM(T2.BalanceAdjustment) AS Balance
FROM Transactions AS T1 INNER JOIN Transactions AS T2 ON (T2.CustomerID=T1.CustomerID) AND (T2.TransactionDate<=T1.TransactionDate) AND (T2.TransactionID<=T1.TransactionID OR T2.TransactionDate<>T1.TransactionDate)
GROUP BY T1.CustomerID, T1.TransactionDate, T1.BalanceAdjustment, T1.TransactionID, T1.TransactionAmount, T1.TransactionType, T1.TransactionDetails, T1.TransactionNotes, T1.[PaymentMethod]
ORDER BY T1.CustomerID, T1.TransactionDate DESC , T1.TransactionID DESC;</CODE>
Thanks for the help!
Kyle
Kevin Yip
@Reply 2 years ago
You don't see Kyle's running balances because your formula for the running balances needs to be modified in order to work for Kyle. If you switch to another customer, the formula has to be changed again to work for that customer. Every time you switch customer, the formula has to be modified. To work for Customer #1, the formula needs the criteria "CustomerID = 1" somewhere in it. To work for Customer #2, it needs "CustomerID = 2", and so on. Does your formula have such a criteria? If not, that is why it only works for all customers, not specific customers. It could be a daunting task keep changing criteria like that. That was why I suggested an alternate method in my previous post. If you have adequate VBA skills, you may consider that route.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.