Page Index Toggle Pages: [1] 2 3  Send Topic Send Topic Print Print
Very Hot Topic (More than 25 Replies) Running Total for subform lines (Read 4365 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Running Total for subform lines
Dec 7th, 2005 at 4:40am
Print Post Print Post  
Maybe someone has been here already.??

I want to have a dynamic running total Cost element in tableview of a subform.  As line items are added/modified/deleted the running total will updated on each line.  Seems like i will need to keep looping when one line changes, starting at record1, to record n.

Execute when enter and exit sub form, when exit Cost element, and when enter parent form?

Same as steps when calculating total for all lines in subform but do subtotal calculation and write to element on each record when counting them and getting total? Element will probably not be bound to anything.

Hmmmm, I think I am almost there, just typing this out has helped to make it more clear in my mind.

Thanks for listening......I guess the tree does make a sound when no one is there to hear it.....
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Running Total for subform lines
Reply #1 - Dec 7th, 2005 at 10:06am
Print Post Print Post  
Never mind, I got it done a few hours ago ......... Grin

But thanks for thinking about it for me .... Cheesy
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Running Total for subform lines
Reply #2 - Dec 8th, 2005 at 6:07pm
Print Post Print Post  
Do you mind sharing what worked for you and maybe a snipit  of the code? 

I will need to do this within the month so any help would be appreciated.

Thanks
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Running Total for subform lines
Reply #3 - Dec 8th, 2005 at 9:43pm
Print Post Print Post  
Glad to oblige

No access to code right now, but should happen in next few
days, possibly later tonight.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Running Total for subform lines
Reply #4 - Dec 9th, 2005 at 12:52am
Print Post Print Post  
Got to it sooner than I thought......here is the code:
Code
Select All
SubRoutine srCalculateTotalCost()

/*
1. Purpose is to calculate a Total for parent form and RunningTotal for subform
2. Structure is Parent Form name is frmParent, subform with natural link is named sfrmChild.
3. Currency element on frmParent, named TotalCost to show total of Cost for all lines in subform.
4. Currenty element on sfrmChild named Cost to show Cost for that individual record.
5. Unbound element on sfrmChild, named RunningTotal, ReadOnly, to show running total for Costs for all records in the subform.
6. Defined as subroutine so can be called on sfrmChild-Cost-OnExitElement and on sfrmChild-Cost-OnFormExit.
*/
//==============================================

var vCount As Int		//Count number of records in subForm
var vLoop As Int		//While loop counter
var vTotal As Double		//Total Cost for all records in subForm
var vRunningTotal As Double	//Running total of Cost

If @FormIsStandalone() = 0 Then {

	vTotal = 0
	vRunningTotal = 0
	vCount = @FormResultSetTotal("sfrmChild")

	vLoop = 1
	While vLoop <= vCount {
		vTotal +=    @ToNumber(@FormFieldValue("sfrmChild","Cost",vLoop))
		vRunningTotal = vTotal
		RunningTotal = vRunningTotal
		vLoop += 1
		}

	If vTotal > 0 Then {
		FormFieldValue("frmParent","TotalCost",0,vTotal)
		}
	}

End SubRoutine
//======================================

 


I have removed other code specific to my application, and changed form names to provide a more generic sample code.

I use a pretty rigid naming convention.  Many elements have a prefix followed by InitialCapsName, no spaces, no underscores.
I use "frm" as a prefix for most forms, and "sfrm" for subforms.
Most variables start with lowercase "v".
SubRoutines use "sr".
Databases start with "tbl".
Text type of elements do not have a prefix, but do use InitialCapsNames.  But the names of the fields that they are bound to in the underlyiing tblDatabase do have a prefix.

But that is a whole other discussion.  Just provided here to help read the sub routine code.
-----------------------------------------------
This is only being used on a test application right now.  I would like to do some more testing in the real world; I am  still concerned about the RunningTotal going onto the correct line item in the proper sequence.  What happens if the lnes are resorted?  Since this is unbound, it should not be a big issue,

I think this code is probably good.  If a line on the subform is deleted, it appears to correct itself, but I am not yet comfortable that this is rock solid.  So use with caution, and any feedback is appreciated.

Edited on 3/8/07. Code sample above was modifed to remove calling function from frmParent.  Problem was found by CapitalG.  Thanks for reporting that.
« Last Edit: Mar 8th, 2007 at 10:25pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Running Total for subform lines
Reply #5 - Dec 9th, 2005 at 4:01pm
Print Post Print Post  
Thank you.  Your help is greatly appreciated.
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #6 - Feb 28th, 2007 at 5:42pm
Print Post Print Post  
Bob_Hansen wrote on Dec 9th, 2005 at 12:52am:
Got to it sooner than I thought......here is the code:
Code
Select All
SubRoutine srCalculateTotalCost()

/*
Purpose is to calculate a Total for parent form and RunningTotal for subform
Structure is Parent Form name is frmParent, subform with natural link is named sfrmChild.
Currency element on frmParent, named TotalCost to show total of Cost for all lines in subform.
Currenty element on sfrmChild named Cost to show Cost for that individual record.
Unbound element on sfrmChild, named RunningTotal, ReadOnly, to show running total for Costs for all records in the subform.
Defined as subroutine so can be called on sfrmCost-OnExitElement and on sfrmCost-OnFormExit,  
Is also defined and called on frmParent-OnFormEntry.
*/
//==============================================

var vCount As Int		//Count number of records in subForm
var vLoop As Int		//While loop counter
var vTotal As Double		//Total Cost for all records in subForm
var vRunningTotal As Double	//Running total of Cost

If @FormIsStandalone() = 0 Then {

	vTotal = 0
	vRunningTotal = 0
	vCount = @FormResultSetTotal("sfrmChild")

	vLoop = 1
	While vLoop <= vCount {
		vTotal +=    @ToNumber(@FormFieldValue("sfrmChild","Cost",vLoop))
		vRunningTotal = vTotal
		RunningTotal = vRunningTotal
		vLoop += 1
		}

	If vTotal > 0 Then {
		FormFieldValue("frmParent","TotalCost",0,vTotal)
		}
	}

End SubRoutine
//======================================

 


I have removed other code specific to my application, and changed form names to provide a more generic sample code.

I use a pretty rigid naming convention.  Many elements have a prefix followed by InitialCapsName, no spaces, no underscores.
I use "frm" as a prefix for most forms, and "sfrm" for subforms.
Most variables start with lowercase "v".
SubRoutines use "sr".
Databases start with "tbl".
Text type of elements have do not have a prefix, but do use InitialCapsNames.  But the names of the fields that they are bound to in the underlyiing tblDatabase do have a prefix.

But that is a whole other discussion.  Just provided here to help read the sub routine code.
-----------------------------------------------
This is only being used on a test application right now.  I would like to do some more testing in the real world; I am  still concerned about the RunningTotal going onto the correct line item in the proper sequence.  What happens if the lnes are resorted?  Since this is unbound, it should not be a big issue,

I think this code is probably good.  If a line on the subform is deleted, it appears to correct itself, but I am not yet comfortable that this is rock solid.  So use with caution, and any feedback is appreciated.


Bob,

We've done a bit of redesigning our database since purchasing Sesame this past Fall.  Thanks for your help awhile back when I asked a question regarding the sizing of our Subform fields  Smiley
I am a complete novice at programming, but searched and found this thread...it looks like what I have in mind for getting a running total of our Parts expenditures in our Repair Subform.  This Subform is linked relationally by Serial Number to our Parent Inventory form.  I'd like to dive in and attempt some programming in a copy of our database.  Your opinion would be invaluable.  

I'll try to post a screenshot of our database.


Charlie


http://us.a2.yahoofs.com/users/456dd110z2ef31adb/f7f4scd/__sr_/3f5fscd.jpgphIDc5...
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #7 - Feb 28th, 2007 at 9:22pm
Print Post Print Post  
Charlie,

When you post your screen shot, give us the specifics of what exactly you want to do. We all like to help and learn.

I see you are in Sacramento, Bob Hansen has a Sesame user group back east (SANE) maybe we can get one going out in California, maybe we can have meetings somewhere between you and LA. Say Bakersfield or ? There must be a bunch of us Sesame users out here that can all benefit from working with each other. Just something to think about.  Smiley

Robert
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #8 - Feb 28th, 2007 at 11:45pm
Print Post Print Post  
BOBSCOTT wrote on Feb 28th, 2007 at 9:22pm:
Charlie,

When you post your screen shot, give us the specifics of what exactly you want to do. We all like to help and learn.

I see you are in Sacramento, Bob Hansen has a Sesame user group back east (SANE) maybe we can get one going out in California, maybe we can have meetings somewhere between you and LA. Say Bakersfield or ? There must be a bunch of us Sesame users out here that can all benefit from working with each other. Just something to think about.  Smiley

Robert


Robert,
I'll definitley be more specific-as much as possible - when attaching a screenshot or anything else

In this "scene" below, I have two databases - the parent is our Inventory, the Subform is derived from our Repair database.  I found that viewing the subform as a Table was, of course, more informative to anyone searching records for any given piece of equipment...the bonus for us when we migrated from Q&A to Sesame, was to be able to confirm, through serial numbers, that a given piece of equipment was actually on our Inventory when we were logging it in for repair without having to open a seperate database.  On our least expensive equipment, we have target Repair amounts*PARTS*) that we look at to make a decision on whether it is cost effective to repair...if the repair Parts  totals are very high and the estimated repair cost approaches 3/4 of the cost of a new machine, we scrap and replace it.  Having our Subform programmed to total our PARTS records when we bring up a specific serial number in search/update mode would be a wonderful thing.  Whether this "Parts Total" calculation was actually displayed within the main  form, the Subform or??? is not critical...as long as we can see the total Parts amount.

On the Table (Subform) you can see "Parts" amounts of:

25.50
22.00
6.00
7.50
140.75
1.00

(I haven't yet sorted the dates in the Repair.db)

We'd like to program the Subform so there is a "Total" amount displayed for "Parts" ...this specific example is a relatively small repair record for one piece of equipment.  We have some items that are  in service and have repairs going back to 1988 (yikes)...20+ repairs for many items.

http://us.a2.yahoofs.com/users/456dd110z2ef31adb/f7f4scd/__sr_/3f5fscd.jpgphIDc5...

I like the idea of a users group "out west" here...time is always at a premuim, but time can always be found for things worthwhile Wink

I'm much "newer" than most here, so please feel free to correct me and slap me around as situations warrant  Roll Eyes

Thwe software is great as is the forum...fantastic resource.
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #9 - Mar 1st, 2007 at 6:51am
Print Post Print Post  
Charlie,

I am not sure I interpreted your explanation correctly but I might be doing something very similar. I have a database that tracks equipment, each piece of equipment is made up of numerous components. When you enter a record for a specific piece of equipment there is a tab that has all components listed. You can choose either Complete. Need or unknown for each component that makes up this piece of equipment. Every time you select need it adds that item to a tab on the form that is a list of needed components. It then automatically does a lookup to my parts vendor database and lists the approved vendor, price and lead time needed for items. It keeps a running total at the bottom so we can identify the total cost to get that piece of equipment running. We then have a button that prints this data out as a service tag with barcode tracking number that stays with the unit or can be used as a purchase order tool. It does almost the same thing for all parts marked unknown; just on a separate tab. below is the subroutines I use to achieve most of this. I am sure there are probably other ways to do what I am doing (probably even better) but this works for me. Just like you I am not a programmer, however Erika and the Lantica team have taught me that anything can be done by the most inexperienced user by just taking your time and breaking the task down into many many steps and just worry about one step at a time. I am not good at posting pictures but if you want I can e-mail screen shots to you. The reason I used the subroutine was because as long as my element name matches my inventory name the only thing I need to do is add the element to my form and it automatically gets added to the entire process. This makes for easy parts additions.

Keep us posted on how your project is going.  Smiley

Robert

P.S. I agree with you Sesame is great!
P.S.S. you do not need to worry about all the @replace code you see below. I needed that for my lookups because my parts database is derived from my vendors inventory database that I constantly use to replace my parts databse and they have a funky format.

Subroutine PartsStatus() // updates parts needed and unknown

// Declare Variables

Var vElements as String
Var vCnt as Int
Var vLoop as Int
Var vName as String
Var vNlist as String
Var vlabel as String
Var vlabel1 as String
Var vvendor as String
Var VVenPartNum as String
Var VVenCost as Double
Var Vline as String
Var Vtotal as Double      
Var VtotalUknown as Double

// Set Variables


     vnlist = ""
       eqp_partsNeeded = ""
     eqp_partsUnknown = ""
     vvendor = ""
     VVenPartNum = ""
     VVenCost = ""
     Vtotal = 0
     VtotalUknown = 0



     vElements = @StringArrayElementList() // Reads all my elements


   
     vCnt = @CountStringArray(vElements) // counts the anount of elements so my loop knows how many times to run
     vLoop = 0


         While vLoop < vCnt
       {
           vLoop = vLoop + 1
           vName = @AccessStringArray(vElements, vLoop)

           SetThisElement(vName)
           vlabel = @label(thiselement) // this gets the label name and assigns it to Vlabel
           
             
//writeln(velements)
//writeln(thiselement + " " + Vlabel) // lists contents of all elements
//writeln(Vname + "stop") // lists all element names


           
                 If Thiselement = "need" Then

                 {      
           
//writeln(thiselement + " " + Vlabel) // lists contents of all elements


                 vlabel1 = @replace(vlabel, "\" , "\\")

                  vlabel1 = @replace(vlabel1, ")" , "\)")
                  vlabel1 = @replace(vlabel1, "(" , "\(")
                  vlabel1 = @replace(vlabel1, "/" , "\/")
                 
                  vlabel1 = @replace(vlabel1, "-" , "\-")
                  vlabel1 = @replace(vlabel1, "." , "\.")
                  vlabel1 = @replace(vlabel1, "&" , "\&")
                  vlabel1 = @replace(vlabel1, "+" , "\+")
//Writeln(vlabel1)
                 Vvendor = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_partVendor")
                 VVenPartNum = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_vendorpartNum")
                 VVenCost = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_vendorpartCost")
                 
                 Vtotal = Vtotal + @tomoney(vvencost)


                 


                 Vline = Vlabel + "  -  " + Vvendor + "  -  " + VvenPartNum + "  -  " + FormatMoney(VvenCost)




                 eqp_partsNeeded =  eqp_partsNeeded  + @newline() + vline

                 Eqp_TotNeedCost =  Vtotal

                 Eqp_TotalCost = Eqp_TotNeedCost + Eqp_UknownNeedCost

                 //writeln(vnlist)
                 }

// ********************

                 If Thiselement = "Unknown" Then

                 {

                 vlabel1 = @replace(vlabel, "\" , "\\")

                  vlabel1 = @replace(vlabel1, ")" , "\)")
                  vlabel1 = @replace(vlabel1, "(" , "\(")
                  vlabel1 = @replace(vlabel1, "/" , "\/")
                 
                  vlabel1 = @replace(vlabel1, "-" , "\-")
                  vlabel1 = @replace(vlabel1, "." , "\.")
                  vlabel1 = @replace(vlabel1, "&" , "\&")
                  vlabel1 = @replace(vlabel1, "+" , "\+")
//Writeln(vlabel1)
                 Vvendor = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_partVendor")
                 VVenPartNum = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_vendorpartNum")
                 VVenCost = @XLookup(@fn, Vlabel1, "VenEqpTrak!VenEqp_partName", "VenEqp_vendorpartCost")
                 
                 VtotalUknown = VtotalUknown + @tomoney(vvencost)


                 


                 Vline = Vlabel + "  -  " + Vvendor + "  -  " + VvenPartNum + "  -  " + FormatMoney(VvenCost)




                 
                 eqp_partsUnknown =  eqp_partsUnknown + @newline() + vline
                 Eqp_UknownNeedCost =  VtotalUknown
                 Eqp_TotalCost = Eqp_TotNeedCost + Eqp_UknownNeedCost
                 }


       }
     UnSetThisElement()
     Throwfocus(nothing)


End Subroutine



Subroutine StatChoices() // choices for equipment itiem status

var Str1 as string
var Str2 as string

// If @isblank(ThisElement)
     
           If ThisElement <> "Complete"



     Then
{
           PopupSelectPosition(4, @XPos(thiselement), @YPos(ThisElement) )
           str1 = "Need;Unknown;Complete"
           Str2 = @popupmenu(Str1, "please Select")
           ThisElement =Str2
}


End subroutine
« Last Edit: Mar 1st, 2007 at 4:12pm by BOBSCOTT »  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #10 - Mar 1st, 2007 at 5:37pm
Print Post Print Post  
BOBSCOTT wrote on Mar 1st, 2007 at 6:51am:
Charlie,

I am not sure I interpreted your explanation correctly but I might be doing something very similar. ...............


Robert,

You are doing something very similar to what we will eventually have running here...You have email.  Thanks for the reply.

Charlie
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #11 - Mar 1st, 2007 at 6:31pm
Print Post Print Post  
Robert,

I received your screenshots...WOW! Shocked Smiley Smiley Smiley

Amazing.  I'm going to be working on a few things in between "other work".  I'll keep you posted on how things go...a little at a time Wink  Many thanks for sharing!

Charlie
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #12 - Mar 5th, 2007 at 6:52pm
Print Post Print Post  
Undecided
Such a simple task, I'm sure...I've taken from examples to try to get programming to run that will total my Parts amount at Search/Update and post that total in filed named "TotalRepairs".  I've tested the code, no errors, but the total is not visible.  My excuse is that I never did any programming in Q&A (or any other software programs).  Bob Hansen's examples are som that we will want to add to our database eventually-amazing stuff; I'd better be able to do some simple programming tasks first.  I will learn to program Sesame...even if I have to take a leave of absence and lock myself in a room for a few weeks Roll Eyes

My subform settings are:

Display Form:  Repair1
Subrecords are "relational" by serial number of my equipment.
Subrecord Field Name: Repair_Subform
Layout Element is: TotalParts

The subform is displayed in Table View on the Parent Form.

We'd like the Parts total (money) to display on the fly during search/update...I've run the code in Global Code with no errors, but no total in my Layout Element

Code I've been attempting is:


SubRoutine CalculateParts()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1  //Record variable

vCount = @FormResultSetTotal("Repair_Subform")

If vCount > 0 Then
{
    While vRecord <= vCount
    {
          //Loop through subrecords adding up totals.
          vTotal = vTotal + @TM(@FormFieldValue("Repair_Subform", "Parts", vRecord))
          vRecord = vRecord + 1
    }

    //Place values in elements on form
    TotalRepairs = vTotal
}
End SubRoutine


  
Back to top
 
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Running Total for subform lines
Reply #13 - Mar 5th, 2007 at 7:45pm
Print Post Print Post  
charliebrown wrote on Mar 5th, 2007 at 6:52pm:

My subform settings are:

Display Form:  Repair1
Subrecords are "relational" by serial number of my equipment.
Subrecord Field Name: Repair_Subform
Layout Element is: TotalParts

The subform is displayed in Table View on the Parent Form.

We'd like the Parts total (money) to display on the fly during search/update...I've run the code in Global Code with no errors, but no total in my Layout Element

Code I've been attempting is:


SubRoutine CalculateParts()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1  //Record variable

vCount = @FormResultSetTotal("Repair_Subform")

If vCount > 0 Then
{
     While vRecord <= vCount
     {
          //Loop through subrecords adding up totals.
          vTotal = vTotal + @TM(@FormFieldValue("Repair_Subform", "Parts", vRecord))
          vRecord = vRecord + 1
     }

     //Place values in elements on form
     TotalRepairs = vTotal
}
End SubRoutine


It appears that you are using the name that you assigned to the subform, rather than the name of the form being displayed as a subform.  You will want to use "Repair1" in place of "Repair_Subform".

-Ben
  
Back to top
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #14 - Mar 5th, 2007 at 10:38pm
Print Post Print Post  
Quote:
charliebrown wrote on Mar 5th, 2007 at 6:52pm:

My subform settings are:

Display Form:  Repair1
Subrecords are "relational" by serial number of my equipment.
Subrecord Field Name: Repair_Subform
Layout Element is: TotalParts

The subform is displayed in Table View on the Parent Form.

We'd like the Parts total (money) to display on the fly during search/update...I've run the code in Global Code with no errors, but no total in my Layout Element

Code I've been attempting is:


SubRoutine CalculateParts()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1  //Record variable

vCount = @FormResultSetTotal("Repair_Subform")

If vCount > 0 Then
{
    While vRecord <= vCount
    {
          //Loop through subrecords adding up totals.
          vTotal = vTotal + @TM(@FormFieldValue("Repair_Subform", "Parts", vRecord))
          vRecord = vRecord + 1
    }

    //Place values in elements on form
    TotalRepairs = vTotal
}
End SubRoutine


It appears that you are using the name that you assigned to the subform, rather than the name of the form being displayed as a subform.  You will want to use "Repair1" in place of "Repair_Subform".

-Ben


I understand completely Ben...thanks for setting me straight there.  Still not getting any data to appear in the TotalRepairs field after editing programming...
I have a link to a few screenshots of the database, subform values...

http://pg.photos.yahoo.com/ph/cspedden/album?.dir=f7f4scd&.src=ph&store=&prodid=...

Programming changes were in Global Code as follows:


SubRoutine CalculateParts()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1 //Record variable

vCount = @FormResultSetTotal("Repair1")

If vCount > 0 Then
{
While vRecord <= vCount
{
//Loop through subrecords adding up totals.
vTotal = vTotal + @TM(@FormFieldValue("Repair1", "Parts", vRecord))
vRecord = vRecord + 1
}

//Place values in elements on form
TotalRepairs = vTotal
}
End SubRoutine

Of course the maddening part of this is that it's more than likely something incredibly simple that's wrong... Embarrassed
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send Topic Send Topic Print Print