Calculate percentage

Posted on 2007-07-26
Medium Priority
Last Modified: 2008-02-01

I have a table "tbl2007_conference" with three fields, "NumberAttendees", "PresenterRating1" and "PresenterRating1_perc"

I'd like the percentage (PresenterRating1/NumberAttendees x 100) to be automatically calculated in the "PresenterRating1_perc" field. Any help would be greatly appreciated.

Question by:p_classic_2000
  • 2
LVL 65

Accepted Solution

rockiroads earned 500 total points
ID: 19576412
Suggestion - not recommend to store calculated fields in table as you can always recalculate easily on forms

do u want to update values in table or sql?
if in sql do this

update tbl2007_conference set PresenterRating1_perc = PresenterRating1/(NumberAttendees * 100)

if in form, use the afterupdate events of PresenterRating1 and NumberAttendees  to do calculation
LVL 61

Expert Comment

ID: 19576442
You should use queries to calculate and display data like this, rater than storing calculated data in your table.

SELECT *,   iif(NZ(NumerAttendees,0) = 0 , 0 ,100 * PresenterRating1/NumberAttendees) as PresenterRating1_perc
From tbl2007_conference

The iif should prevent divide-by-zero errors if NumberAttendees is 0.

Author Comment

ID: 19576674
Perfect, thanks rockiroads!
LVL 65

Expert Comment

ID: 19576682
no probs
do think about not storing calculated values though, it may sound easy now but its more hassle than its worth

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question