Hot Topic (More than 10 Replies) Totals of a sub-form (Read 2263 times)
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Totals of a sub-form
Aug 5th, 2004 at 11:42pm
Print Post Print Post  
I have a tabbed form and on one I have a subform with items used how do I display a "Grand Total" of all items used of this form from the subform?   ???
  
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Totals of a sub-form
Reply #1 - Aug 6th, 2004 at 12:54am
Print Post Print Post  
Heres a basic little program. Subformname should be the name of the subform. Double check my work for errors in quotations and spelling, just in case.

var a as int =1
var vmax as int = @formresultsettotal(subformname)
var vgrandtotal as double = 0

while a <= vmax
{
vgrandtotal = vgrandtotal + @formfieldvalue("subformname", "total", a)
a=a+1
}

writeln("The Grand Total is "+ vgrandtotal)

Good luck!

Steve
  
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #2 - Aug 6th, 2004 at 1:03am
Print Post Print Post  
Thanks Steve  Cheesy
  
Back to top
 
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #3 - Aug 6th, 2004 at 12:23pm
Print Post Print Post  
Not getting the results expected, the code works but I have 3 items used a 3.00,2.00,1.00 when it adds these up it displays "321" instead of the expected "6.00" will keep working with it, any more ideas appreciated !!   Wink
  
Back to top
 
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #4 - Aug 6th, 2004 at 12:28pm
Print Post Print Post  
Also I want the Grandtotal displayed in a field on the bottom of the tab containing the subform?  Not asking for much am I.  Kiss
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Totals of a sub-form
Reply #5 - Aug 6th, 2004 at 12:43pm
Print Post Print Post  
Proudpoppy,

It looks like you are adding strings together, rather than numbers. If you post your actual code it will be easier to spot the specific problem.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #6 - Aug 6th, 2004 at 12:58pm
Print Post Print Post  
The code I'm using is what is listed above from Steve I only changed line 2 "(subformname) to ("itemsused") and line #5 the same to my subformname(itemsused).I put this code in a element on my tabbed form containing the sub form called "Grandtotal" I dropped the "Writeln" hoping it would just display it in the element, but no luck.
  
Back to top
 
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #7 - Aug 6th, 2004 at 12:59pm
Print Post Print Post  
Also the fields I trying to add are "Money fields".
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Totals of a sub-form
Reply #8 - Aug 6th, 2004 at 1:16pm
Print Post Print Post  
Quote:
I put this code in a element on my tabbed form containing the sub form called "Grandtotal" I dropped the "Writeln" hoping it would just display it in the element, but no luck.


Again, if you post your actual code, we can be of more help. Just copy and paste your code into a post, so we can see what you're doing. @FormFieldValue always returns a string, so something probably just needs to be wrapped in @ToNumber( ).
Code
Select All
vgrandtotal = vgrandtotal + @ToNumber(@formfieldvalue("subformname", "total", a))
...
MyElement = vgrandtotal 



  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #9 - Aug 6th, 2004 at 1:30pm
Print Post Print Post  
Here it is:

var a as int=1
var vmax as int = @formresultsettotal("Itemsused")
Var vgrandtotal as double = 0

while a <=vmax
{
vgrandtotal=vgrandtotal + @formfieldvalue("Itemsused","Total",a)
a=a+1
}

I get nothing in the element I put this code in unless I put the "Writeln Statement back in"
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Totals of a sub-form
Reply #10 - Aug 6th, 2004 at 1:37pm
Print Post Print Post  
You need to actually assign the final value to your element. Try this:
Code
Select All
 var a as int=1
var vmax as int = @formresultsettotal("Itemsused")
Var vgrandtotal as double = 0

while a <=vmax
{
vgrandtotal=vgrandtotal + @ToNumber(@formfieldvalue("Itemsused","Total",a))
a=a+1
}
MyElementName = vgrandtotal 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Totals of a sub-form
Reply #11 - Aug 6th, 2004 at 1:42pm
Print Post Print Post  
Also, you need to make sure you are putting the above program in the right place.

Maybe in a command button's "On element entry", or in a preceeding element's, "On element exit", or even in "MyElementName's" On element entry.

Just my .02 cents.

Steve
  
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Totals of a sub-form
Reply #12 - Aug 6th, 2004 at 2:12pm
Print Post Print Post  
That did it, thanks for all the input.    Cheesy
  
Back to top
 
IP Logged