Solved

Running balance on subform

Posted on 2003-11-14
11
605 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
[X]
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
  • 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
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.

 

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

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

726 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