Solved

Running balance on subform

Posted on 2003-11-14
11
576 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
 

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Time Error 3075 15 44
MS Access Calculation wont work 5 35
Export Query data to excel file 14 33
Access 2010 Query Syntax 5 21
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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

911 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

16 Experts available now in Live!

Get 1:1 Help Now