PDA

View Full Version : Sum as type...


sukkarfarid
Oct 15, 2006, 02:52 AM
http://www.moq3.com/pics/up/g_11_10_06/7190c4c32e.jpg (www.moq3.com)

http://www.moq3.com/pics/up/g_11_10_06/ad7956cd79.jpg (www.moq3.com)

http://www.moq3.com/pics/up/g_11_10_06/f3a4e126de.jpg (www.moq3.com)

http://www.moq3.com/pics/up/g_11_10_06/fcbe752fc5.jpg (www.moq3.com)

Thanks a lot
Farid Sukkar

ScottGem
Oct 15, 2006, 04:30 AM
It would help if you told us what platform you are working in. The code appears to be Access VBA. So I'll answer for that.

First you don't actually need any code to do this. If you set the ControlSource of the No3 Control to:

=IIF([Type] = "Output",([No1]*-1)*[No2],[No1]*[No2])

That will do what you want.

Second, As a general rule we do NOT store calculated values. Therefore to sum the results, you need to use a query. In Query Design mode add your table and add the three fields (Type, No1, No2). Then add a 4th column with the expression:

No3: IIF([Type] = "Output",([No1]*-1)*[No2],[No1]*[No2])

Now on your form, add unbound controls with a ControlSource of:

=DSUM("[No3]","Queryname","[Type] = 'Output'")
=DSUM("[No3]","Queryname","[Type] = 'Input'")

sukkarfarid
Oct 17, 2006, 12:52 AM
thank you ScottGem for help me...
I try the code you give to me... and I have a problem... that the sum of result of all
input , and of all output..

I upload to you the program picture , and I upload to you my test program...
http://www.moq3.com/pics/up/g_15_10_06/ec36096e9e.jpg (www.moq3.com)

please help me.. thank you very much to you .
Best Regards
Farid Sukkar

ScottGem
Oct 17, 2006, 07:09 AM
I told you what to do, using the DSUMs. Did you try that?

sukkarfarid
Oct 31, 2006, 02:04 AM
thank you for help me...
I try the query , and it's a successfully query...
I have question for this query...
when I input the data on the table the sum of this data not show , but when I go to next record and back to my record , the sum of data appears .

how I can when I input the data the... the sum appear direct

Thnaks
Farid

ScottGem
Oct 31, 2006, 06:26 AM
Again, as a general rule we don't store calculated values. Use the DSum to display the value wherever needed.