473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Trying to calculate a Sum

I have a table with 5 fields into which the user will enter numbers,
which must add up to 100%. Say the fields are Toyotas, Missans, Mazdas,
Hondas and Other. I am having trouble writing a query using Sum which
will add these together and place the result in another field called
"total" which I will then place on a form so the user can check it
contains value 100 for each record. Any help appreciated, thanks.

Nov 13 '05 #1
7 1805
If your fields are called Toyota, Nissan etc

Use an unbound field called Total

In its record source write

=Toyota+Nissan+Mazda+Honda+Other

then as you update the fields Honda, Toyota etc the total will change
showing the current sum.

You could use a VB procedure to do the same which would allow you to
test to see if the answer is less than a hundred or more than a hundred
and pop up a message box with an appropriate warning.

Nov 13 '05 #2
In article <11**********************@g47g2000cwa.googlegroups .com>,
ge***@sunny-side.ws opined thusly:


If your fields are called Toyota, Nissan etc

Use an unbound field called Total

In its record source write

=Toyota+Nissan+Mazda+Honda+Other


Sorry, I'm not that great at this yet...where do I create this? I have
succeeded in creating an unbound text frame in the form design view but I
can't see where it's "record source" is. I did succeed in getting it to echo
the value from one of the fields but when I used the expression builder to
sum them, it appended the digits instead

ie. 10, 30, 20, 5, 35 became 103020535 instead of 100.

thanks.

Nov 13 '05 #3
Are these car names the columns in a database table
or just text boxes on a form?

Nov 13 '05 #4
In article <11**********************@g43g2000cwa.googlegroups .com>,
th***********@gmail.com opined thusly:


Are these car names the columns in a database table
or just text boxes on a form?


They are each fields in a table. I worked my way through the Access Help
info on summing, and followed the instructions no problem to create the
unbound text box and then fill it with the expression:

=[toyota]+[mazda]+[nissan]+[honda]+[other]

but still it appends the percentages into a 10 digit integer instead of
adding them together!

Nov 13 '05 #5
What are the data types of those columns?

Nov 13 '05 #6
Assuming you have 5 fields on a form, you should be able to force a constant
sum of 100% across the fields, making user verification unnecessary.

For example, start with 20% in each of the 5 fields. When one of the fields
changes value, distribute 100 - [sum of modified fields] evenly across the
remaining unmodified fields. So if the user changes the Toyota field to 30%,
mark the Toyota field modified and distribute (100-30)/4 to each of the 4
remaining unmodified fields. And if the user then changes the Honda field to
25%, distribute (100-55)/3 to each of the 3 remaining unmodified fields.
Etc.

I suppose you will need some global variables (maybe an array?) to keep
track of which fields have been modified/marked; and you will probably need
a Reset button to reset the fields to the default 20% and unmark all fields,
if the user wants to start over; and you probably want to round to 2
decimals to force the math to be exactly right.

Ok, maybe the code gets a little complicated. Should be possible, however.

"richard" <no****@myplace.net> wrote in message
news:xJ******************@news-server.bigpond.net.au...
I have a table with 5 fields into which the user will enter numbers,
which must add up to 100%. Say the fields are Toyotas, Missans, Mazdas,
Hondas and Other. I am having trouble writing a query using Sum which
will add these together and place the result in another field called
"total" which I will then place on a form so the user can check it
contains value 100 for each record. Any help appreciated, thanks.

Nov 13 '05 #7
Maybe my idea is not so workable, after all. I'm concerned about the
possibility of causing an infinite loop which might happen if a user change
to one form field triggers code in another form field which in turn
retriggers the code in the original field, etc. Ugh.

"Mondrogan" <mo*******@comcast.net> wrote in message
news:qb********************@comcast.com...
Assuming you have 5 fields on a form, you should be able to force a
constant sum of 100% across the fields, making user verification
unnecessary.

For example, start with 20% in each of the 5 fields. When one of the
fields changes value, distribute 100 - [sum of modified fields] evenly
across the remaining unmodified fields. So if the user changes the Toyota
field to 30%, mark the Toyota field modified and distribute (100-30)/4 to
each of the 4 remaining unmodified fields. And if the user then changes
the Honda field to 25%, distribute (100-55)/3 to each of the 3 remaining
unmodified fields. Etc.

I suppose you will need some global variables (maybe an array?) to keep
track of which fields have been modified/marked; and you will probably
need a Reset button to reset the fields to the default 20% and unmark all
fields, if the user wants to start over; and you probably want to round to
2 decimals to force the math to be exactly right.

Ok, maybe the code gets a little complicated. Should be possible, however.

"richard" <no****@myplace.net> wrote in message
news:xJ******************@news-server.bigpond.net.au...
I have a table with 5 fields into which the user will enter numbers,
which must add up to 100%. Say the fields are Toyotas, Missans, Mazdas,
Hondas and Other. I am having trouble writing a query using Sum which
will add these together and place the result in another field called
"total" which I will then place on a form so the user can check it
contains value 100 for each record. Any help appreciated, thanks.


Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
11
by: hazz | last post by:
before I start filling up the first page of perhaps many pages of code with if/then or switch:case buckets, I wanted to step back and see if there is a better way... I will have a table with up to...
2
by: Pixie Songbook | last post by:
Hi, I have a progarm which models some data I'm working with using a gaussian profile and then calculates chi-squared in order to compare the gaussian values to the real thing. I want to minimise...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
3
by: erikcw | last post by:
Hi, I'm getting the following error when I try to pass a list into a function. My List: crea = Traceback (most recent call last): File "wa.py", line 118, in ? curHandler.walkData()
3
by: Widge | last post by:
I have made a spreadsheet that will calculate the distance from a set of addresses to a specified postcode in Excel. I'm looking to move this to Access so I can start thinking about hooking it up to...
5
by: brendanmcdonagh | last post by:
Hi, I have been learning VB now for about a week and thought I was doing ok. I have already done a calculation form (not as big as this) . I have volunteered myself to help a friend input her hours...
12
by: denveromlp | last post by:
Hello, I'm new to Access and trying to calculate a rolling 12 month average from some time data. Each data point is a date and a measurement taken at that date. As far as I can tell, the only...
3
by: strangetorpedo | last post by:
The problem lies under where if (choice == '2') is...I need the program to keep prompting for num and den values as long as the user enters values less than or equal to 0. Once they are values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.