Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 631
  • Last Modified:

Running balance on subform

See also http://www.experts-exchange.com/Databases/MS_Access/Q_20756831.html.

I need to calculate a running balance on a subform.  On the main form I have a total amount due.  The subform takes in payment amounts.  See below:

Total Amount Due: $10.00

Date Paid:  Amount Paid:  Balance:
10/24/03    2.00               8.00
10/25/03    4.00               4.00
11/1/03      2.00               2.00

I can't get the balance to work.  It needs to be that the first entry is Total Amount Due - Amount Paid = Balance.  Every entry after that needs to be Previous Balance - Amount Paid = Balance.  

Please help!  I need this ASAP!  Thank you so much!
0
drache21
Asked:
drache21
  • 5
  • 5
1 Solution
 
morpheus30Commented:
Hi drache21:

Create an invisible unbound TextBox in your subform that you'll use to track all payments.  Name this textbox txtPayments.  Create a function in the onCurrent Event that adds all the payments made into the value of this textbox, like:

sql = SELECT SUM(AmountPaid) AS SumOfPayments FROM PaymentsTable

txtPayments.Value = rs(SumOfPayments)

Then Create a VISIBLE textbox called "txtBalance" that tracks the running balance like this:

txtBalance = Parent.txtAmountDue -  txtPayments.

If you need help with the full VBA code, I'll need to know more about your tables, and form names, etc...
0
 
morpheus30Commented:
Oh, I forgot...

You'll also need to create an OnUpdate event to the form to do the same thing...
0
 
drache21Author Commented:
Please forgive me - I'm a newbie.  Where do I create the function in the OnCurrent event?  In the text box txtPayments?  There wasn't an onCurrent event option.

I'm sorry if this is a dumb question!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
drache21Author Commented:
I think I figured it out.  The onCurrent event is on the subform, right?  In that case I may need a little help with the coding.  What do you need to know?
0
 
morpheus30Commented:
OK, I need the name of the text box holding the Amount Due on the main form.   I also need the name of the table holding your Payments and the name of the table (if separate) that holds your charges.
0
 
drache21Author Commented:
The text box holding the Amount Due on the main form is LA Total, the name of the table holding the payments is tblLAPaid, and I'm not sure what you mean by charges.  If you mean the table that holds total Amount Due, it's tblCaseInfo.  Please let me know if this is unclear.  :)  Thank you so much!
0
 
morpheus30Commented:
Hey Drache21:

Yes, I'll need a little more info.  If you could copy and paste your tables with a few lines of data like this:

tblLAPaid
PaymentID  PayeeID  Amount    Date             AccountRef
1                345        20            10/3/2003    100329
2                345        20            10/10/2003  100329
3                345        20            10/17/2003  100329

tblCaseInfo
AccountRef   ItemDescription        AmountDue
100329        Flat Screen Monitor   250

tblPayee  
PayeeID   FirstName   LastName
345         Larry           Williams

0
 
drache21Author Commented:
tblLAPaid
Case Number     Amount Paid     Date Paid
1                      2.00                 11/04/03

tblCaseInfo
Case Number  Last Name  First Name  Middle Name  (cont'd)
1                   Doe            John           James

Conviction Date  First Payment  Closed Date  LA Total  (cont'd)
1/1/03              1/2/03             11/05/03     200.00

State Total  LA Penalty  State Penalty  Notes
300.00        500.00       500.00           Blah Blah Blah  

I don't have a table for Payee.  The payee is always the case name.  Does this make sense?  Thank you!
0
 
drache21Author Commented:
tblLAPaid
Case Number     Amount Paid     Date Paid
1                      2.00                 11/04/03

tblCaseInfo
Case Number  Last Name  First Name  Middle Name  (cont'd)
1                   Doe            John           James

Conviction Date  First Payment  Closed Date  LA Total  (cont'd)
1/1/03              1/2/03             11/05/03     200.00

State Total  LA Penalty  State Penalty  Notes
300.00        500.00       500.00           Blah Blah Blah  

I don't have a table for Payee.  The payee is always the case name.  Does this make sense?  Thank you!
0
 
morpheus30Commented:
Hey Drache:

Sorry I couldn't get back to you with the code sooner, but I was swamped with work yesterday and I could not even get it started for you.  I'm not as busy today, but I don't think I'll be able to get back to you as quickly as I could last week.

To save time, I'm assuming that you have already put together a Form with a Subform that shows payment records for a given case number.  I also assume that you know a little bit about Access controls like Texboxes, ComboBoxes, etc. and how they relate to the form in VBA.  You can tailor the following code to your needs....

First your form should have a ComboBox named "cboCaseNumber" on the Main form.  The main form should also have 3 other textboxes named: LATotal, txtTotalPayments, and txtBalance (txtTotalPayments should be invisible when you're ready to use the application).

Open the subform in design view and paste the following code in the "After Update" event between the Private Sub Form_AfterUpdate() and End Sub statements.

Dim db As Database
Dim rs As Recordset
Dim sql As String

Set db = CurrentDb()
sql = "SELECT SUM([Amount Paid]) AS TotalPayments FROM tblLAPaid WHERE [Case Number] = " & Parent.cboCaseNumber.Value
Set rs = db.OpenRecordset(sql)

Parent.txtTotalPayments = rs("TotalPayments")
Parent.txtBalance = Parent.LATotal - Parent.txtTotalPayments

rs.Close
Set rs = Nothing

Then Open the Main form in design view and paste the following code in the OnCurrent event:

Dim db As Database
Dim rs As Recordset
Dim sql As String

Set db = CurrentDb()
sql = "SELECT SUM([Amount Paid]) AS TotalPayments FROM tblLAPaid WHERE [Case Number] = " & cboCaseNumber.Value
Set rs = db.OpenRecordset(sql)

txtTotalPayments = rs("TotalPayments")
txtBalance = LATotal - txtTotalPayments

rs.Close
Set rs = Nothing

And then copy the following code in the "After Update" event of the main form:

Call Form_Current

That's it!

Good Luck!!!

0
 
ornicarCommented:
----------------------------------------------------------------------------------------
This question has been abandoned and needs to be finalized.
 You can accept an answer, split the points, or get a refund (information at http:/help.jsp#hs5)
  If you need a moderator to help you, post a question at Community Support (http:/Community_Support/)

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ornicar
Cleanup Volunteer

---------------------------------------------------------------------------------------------
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now