473,403 Members | 2,359 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,403 software developers and data experts.

Sum of calculated values in datasheet form

79 64KB
In a datasheet form I have the following Text Boxes. This datasheet form is embedded in a main form where the formula ID is linked. The datasheet form’s record source is bound to a Query named Q_Formula.

1. “txt_FormulaID” stores formula ID.
2. “txt_ID” stores component ID.
3. “txt_ComponentName” stores component name.
4. “txt_QTY” allows user to enter quantity. Data Control Source bound to field “QTY”.
5. “txt_UOM” allows user to choose unit of measure, i.e., Lb, Oz, Kg, or G. Data Control Source bound to field “Unit”.
6. “txt_Conv” has Data Control Source bound to a calculated field, ConvWT, in the Query. The calculation is to convert the value in the txt_QTY to a new value based on gram. So far, this is working fine. The syntax is listed below.
7. “txt_Sum” is placed in the form footer and is supposed to sum all values in “txt_Conv”, but I cannot manage to make this work.
8. “txt_Wt%” is to calculate and return weight percentage of each component based on the calculated value in txt_Conv. This is where I am stuck, too.

Below is the syntax that I placed in the calculated Field in the query that bound to txt_Conv.

Expand|Select|Wrap|Line Numbers
  1.  ConvWT: IIf([Unit]="G",[QTY],IIf([Unit]="KG",[QTY]*1000,IIf([Unit]="OZ",[QTY]*28.35*1000,IIf([Unit]="LB",[QTY]*16*28.35*1000,0)))) 
Below is the syntax in Control Source of “txt_Sum” that is supposed to calculate the sum of values in “txt_Conv”. But Access returns #Error in this textbox. As consequence, the “txt_Wt%” also has #Error shown.

Expand|Select|Wrap|Line Numbers
  1.  = SUM([txt_Conv]) 
I read some posts related to this subject, but I still cannot figure out how sum function works for calculated values.

Please help.
Thanks in advance!
Mar 20 '12 #1

✓ answered by NeoPa

Have you tried the obvious answer :
Expand|Select|Wrap|Line Numbers
  1. =Sum([ConvWT])
PS. Try the following simpler statement for ConvWT :
Expand|Select|Wrap|Line Numbers
  1. ConvWT: [QTY] * Switch([Unit]='G',1,[Unit]='KG',1000,[Unit]='OZ',28350,[Unit]='LB',453600,True,0)

4 3909
NeoPa
32,556 Expert Mod 16PB
Have you tried the obvious answer :
Expand|Select|Wrap|Line Numbers
  1. =Sum([ConvWT])
PS. Try the following simpler statement for ConvWT :
Expand|Select|Wrap|Line Numbers
  1. ConvWT: [QTY] * Switch([Unit]='G',1,[Unit]='KG',1000,[Unit]='OZ',28350,[Unit]='LB',453600,True,0)
Mar 21 '12 #2
Joe Y
79 64KB
NeoPa,

Thanks for the quick response. While I was trying to test the code you suggested, I realize that my query is not functioning (not editable). Something changed when I tried to make the sum function works.

I will report back when I figure out what have failed my query.

Thanks,
Joe
Mar 21 '12 #3
Joe Y
79 64KB
NeoPA,

You were right. The soluntion of my question was obvious quite simple. The Sum function of calculated field in this case should refer directly to the field in the query instead of the texbox name.

Also, thanks for the tips of the Switch function. I did not know what it does. It certainly make this code cleaner.

Joe
Mar 22 '12 #4
NeoPa
32,556 Expert Mod 16PB
Joe Y:
You were right. The soluntion to my question was obviously quite simple
Actually, this is an issue that confuses many. If you learn it then you will be in a good position to avoid such problems in future.

PS. Another function that often proves worthwile when selecting between multiple options is Index(). I'll let you look that one up in Context-Sensitive Help ;-)
Mar 22 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stefanos | last post by:
Hi everybody, I need some help on calculated values in my database design. I'm creating an accounting / business management application with the usual modules like A/R, A/P, Inventory, etc. ...
1
by: SJH | last post by:
I have been given an older database and asked to make upgrades and what not. One interesting thing I have come across with the database is that it was at one time set up so one of the tables would...
3
by: CLarkou | last post by:
Is there any way to get the record(s) the user has selected in a Datasheet form ?
2
by: CLarkou | last post by:
Is there any other way of looping in the fields of records in a Datasheet form, except from the following one (moving to each record) for checking the field values ? For I = 1 To var_end_R...
1
by: douh | last post by:
I know that this is not the way, however I need to save certian calculated values so that they do not change over time, ie. new tax rates etc. This is for an invoice header and invoice subform. I...
2
by: Arnie | last post by:
I have searched this NG for datasheet column width posts and have read many of them. None of them seem to address what I would like to do. I'm beginning to think what I want can't be done. Here...
1
by: Thelma Lubkin | last post by:
I have a form that allows a user to choose a specific field value. The form calls a second, datasheet, form using a different field in the selected record as a filter . This second form has a...
11
by: James Hallam | last post by:
I have read through all the past topics and couldn't find what I was after so... I am looking to store some calculated values (don't flame just yet, just read on!). I have an piece of code...
24
by: NaftoliGug | last post by:
Is there a way to have unbound, uncalculated controls (or a calculated control that is based on a function) that retains a different value for each record?
5
by: royals | last post by:
Hello Access gurus, I am a self-taught Access “developer” and have a ton to learn so please allow me to sound stupid. I am using 2003 on a XP platform. I manage properties for an...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.