Solved

Running balance on subform

Posted on 2003-11-14
11
561 Views
Last Modified: 2010-08-05
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
Comment
Question by:drache21
  • 5
  • 5
11 Comments
 
LVL 5

Expert Comment

by:morpheus30
Comment Utility
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
 
LVL 5

Expert Comment

by:morpheus30
Comment Utility
Oh, I forgot...

You'll also need to create an OnUpdate event to the form to do the same thing...
0
 

Author Comment

by:drache21
Comment Utility
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
 

Author Comment

by:drache21
Comment Utility
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
 
LVL 5

Expert Comment

by:morpheus30
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:drache21
Comment Utility
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
 
LVL 5

Expert Comment

by:morpheus30
Comment Utility
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
 

Author Comment

by:drache21
Comment Utility
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
 

Author Comment

by:drache21
Comment Utility
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
 
LVL 5

Accepted Solution

by:
morpheus30 earned 135 total points
Comment Utility
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
 
LVL 9

Expert Comment

by:ornicar
Comment Utility
----------------------------------------------------------------------------------------
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now