Adding values in two feilds based on condition

M

Muthiah

Hello,

I am trying to write a program to in vb application , which should add
values from two feilds from same table based on condition.



My requirement is - there are two fields in database from the same table and
i generating a report in acess. in that report , i want the two feilds based
on condition.



Feild A Field B
1 5
2 null
0 1

i want to make sum of feild based on conditon ,condition should apply till
the end of database records

Grand Total should be arrived = 5+2+1= 8


Always feild B value should the first priority

when there is value in both field B and feild A, The value of feild B should
be taken for sum. when there is no value in Feild B, the value of Field A
should added to grand total of Feild b. when there is no value or value is
zero in Field A , feild b should be added to grand total.

Logic is Feild B should be summed and compared with the feild A with the
above condition and added to grand total . I have metenioed the grand total
as 8 with the logic example.
compare the first record and it should pick valuve 5 and add to the grand
total and second record take2, since feild B is null, for the third record
take feild B value as 1, since feild A is 0. which is 5+2+1. the grand total
should be 8 at the bottom of the report.

I would appreiciate your help. I am system admin , no idea about programing.
I making this report for calaucalting disk utlilzation storage farm for my
montly report

Thanks

Muthiah
 
D

Douglas J. Steele

In the query on which the report is based, add a computed field Nz([FieldB],
[FieldA]) and sum that field.

If there's a chance that FieldA might be Null, use Nz(Nz([FieldB],
[FieldA]), 0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top