Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubble Calculate??

Status
Not open for further replies.

Fekri

Programmer
Jan 3, 2004
284
IR
Hi,

I have 3 column in my report, which I need to calculate in one of them "column1-column2"

ok, this I did. but in the form footer, i have to make sum all the data, which is in column3.

So, I made an event in "on format" of report detail like this:
dim s
column3=column1-coulmn2
s=s+column3

And in "on format" of report footer:

[text32]=s

Finally, every thing is good but the result value is *2,
I checked by break and I found the detail event will run and calculate 2 time but I don't know why and why the value of lines in detail is not *2?????

can you help me???

thanks
Ali


 
Instead of s=s+column3, use a running sum for "column4". You can use Sum in the report footer:
[tt]Sum(Column1-Column2)[/tt]

Don't forget that you can hide controls, if you wish.
 
Keep in mind that format events usually fire at least twice
for reports, so you will perform any calculations in these events twice.

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
Forgot to add: That's why Remou's example will work well - it will always return a sum of data, rather than incrementing a variable!

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
Thanks to all,

But I had to use my method event to calculate other value too.

I found my mistake:

I was made Running sum in column3 before and I didn't know, and when I removed it the calvulation event run one time.

thank you to all.
Ali
 
Fekri,
I still think it is a mistake to write any code to aggregate values when you can generally use simple expressions in control sources. If you want the sums of Column1 - Column2, you should be able to add a text box to the report footer section with a control source of:
=Sum(Column1 - Column2)
This would need modification if what you refer to as "in the form footer" is actually the report's Page Footer section.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks dhookom,

yes, you are right.

Appreciate your advise and thanks a lot

best regards
Ali Fekri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top