Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Running balance on subform

Posted on 2003-11-14
11
596 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
ID: 9750940
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
ID: 9750947
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
ID: 9751263
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:drache21
ID: 9751281
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
ID: 9751427
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
 

Author Comment

by:drache21
ID: 9752096
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
ID: 9764999
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
ID: 9765182
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
ID: 9765183
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
ID: 9772445
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
ID: 10063812
----------------------------------------------------------------------------------------
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

861 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