Normal Topic Running balance. (Read 552 times)
drastixnz
Full Member
***
Offline


A Newbie....

Posts: 146
Location: New Zealand
Joined: Nov 29th, 2006
Running balance.
Nov 18th, 2007 at 9:12pm
Print Post Print Post  
I have a subform, that has a balance I am wanting to enter in a payment on that same subform, agasit the balance. which will give me a new balance, example.


ID         Payment      Balance
123                          $300
123       $100            $200
123       $200            $0

Any help would be great
  
Back to top
IP Logged
 
MP
Full Member
***
Offline



Posts: 104
Joined: Sep 3rd, 2007
Re: Running balance.
Reply #1 - Nov 19th, 2007 at 12:23am
Print Post Print Post  
Something like this should work.  Using the Subform tutorial, I added a "Balance" field to the LineItems subform and put the following code in the On Form Change event of the parent form:
Code
Select All
var vintRecordNumber as Int
var vintCurrentPosition as Int
var vintResultSetTotal as Int
var vmnyBalance As Money
var vintCurrentPosition = @FormResultSetCurrentPosition( "LineItems" )
var vintResultSetTotal = @FormResultSetTotal( "LineItems" )

//Verify that we're not currently adding a record to the subset
If vintCurrentPosition <= vintResultSetTotal Then
{
	//Set an initial balance.  This value should likely be obtained from a field in the parent form.
	vmnyBalance = 300

	//Anal variable initialization.
	vintRecordNumber = 0

	//Loop through all of the records in the subform.
	While vintRecordNumber < vintResultSetTotal
	{
		vintRecordNumber = vintRecordNumber + 1
		vmnyBalance = vmnyBalance - @TOMONEY(@FormFieldValue("LineItems", "Price", vintRecordNumber ))
		FormFieldValue("LineItems", "Balance", vintRecordNumber, vmnyBalance )
	}
}
 


Note that I would strongly advise that the Balance field exist as an unbound calculated field.
« Last Edit: Nov 26th, 2007 at 6:25pm by Hammer »  
Back to top
 
IP Logged
 
drastixnz
Full Member
***
Offline


A Newbie....

Posts: 146
Location: New Zealand
Joined: Nov 29th, 2006
Re: Running balance.
Reply #2 - Nov 19th, 2007 at 2:12am
Print Post Print Post  
Thank you MP
  
Back to top
IP Logged
 
drastixnz
Full Member
***
Offline


A Newbie....

Posts: 146
Location: New Zealand
Joined: Nov 29th, 2006
Re: Running balance.
Reply #3 - Nov 20th, 2007 at 9:57pm
Print Post Print Post  
After reading an comment on the post, which was removed I have taken there advice and made some reports to do the work needed.
  
Back to top
IP Logged