percentage in a form

L

LA

Hello,

i want to calculate a % of the locals content against nationals i.e
=locals/(nationals+locals) f.e if locals 23, nationals 4, the locals content
% will be 85.19%
I don't know how to set this calcuation in a form so it could automotically
calcuate after I will enter locals & nationals quantity? Could you please
help which formula to use? Thanks in advance
 
K

Keith Wilby

LA said:
Hello,

i want to calculate a % of the locals content against nationals i.e
=locals/(nationals+locals) f.e if locals 23, nationals 4, the locals
content
% will be 85.19%
I don't know how to set this calcuation in a form so it could
automotically
calcuate after I will enter locals & nationals quantity? Could you please
help which formula to use? Thanks in advance

Use your formula in a query and base your form on that query:

MyField: [locals]/([nationals]+[locals])

Keith.
www.keithwilby.co.uk
 
B

Brian

Assuming text box Nationals and another text box Locals, then put this in the
ControlSource of third box LocalsContent:

=IIf(Nz(Locals,0)>0 Or
Nz(Nationals,0)>0,Nz(Locals,0)/(Nz(Nationals,0)+Nz(Locals,0)),Null)

Format LocalsContent as a Percent.

The Iif & Nzs just ensure that the result is null if both values are null or
0, thus preventing the divide by 0 error that would occur if Locals +
Nationals = 0. This also assumes you do not allow negative values (thus
avoiding Locals 1, Nationals -1, which would also result in a divide by 0
error).

My solution is a little over-simplified in that the value will be 0 whenever
Locals is null or 0, thus showing 0 before the user enters any value for
Locals; a nested IIf could handle this as well if necessary.
 

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