MS Access Calculated form fileds

Posted on 2011-03-01
Medium Priority
Last Modified: 2012-05-11
I have been living in this forum for a couple of days gaining lost knowledge of MS Access. Apparently not working with he program for many years you forget things...

here is full scenerio:
fields are [number][choice][choicecost][yes][totalcost] and [grouptotal]

I have successfully got a dropdown combo box chose to populate a couple of fields
the  choice made in list populates the field [choice] and [choicecost] i have a yes or no check box [yes] that can add $5 if "yes" to the [choicecost] result which I want to be populate in [totalcost]. The I need to multiply [totalcost] by [number] to populate [grouptotal].

first I can't seem to populate the [totalcost] field. I have tried a textbox withe the control source =
"=IIf([yes]=1,([choicecost]+5),[choicecost]) but I get the #Name? error
Iwas going to attempt to popluate that result of the textbox to the [totalcost] field.
I then tried the query option but got no results at all.

Once I get that to work Iwas going to tackle the [grouptotal] calculations.

any help would be great! (keep in mind I have not been using access for many years and my knowledge is much less than i thought.

Question by:Bill Doherty
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4

Expert Comment

ID: 35014002
My first thoughts center on your names for the 'number' and 'yes' fields:

- 'number' is a property
- 'yes' is part of the 'yes/no data type.

I don't know for sure that this is problematic but I feel uncomfortable with the names and would like to suggest 'Quantity' instead of 'number' and 'ChFlg' for 'yes'.

The other problem lies with the [yes] = 1 condition in the iif statement.  I think 'False' or an unchecked checkbox has a numeric value of zero and a checked ( 'True' ) checkbox has a non-zero numeric value - and may be -1.

Then [totalcost] control soure becomes

 = iif( [ChFlg] = True, [choicecost] + 5, [choicecost] )

and [groupcost] control source becomes

= [Quantity] * [totalcost]

LVL 22

Expert Comment

ID: 35020288
I've also seen many cases where the form wizard created control names that match the field names then gets confused then you build calculated formulas.

If you have controls on the form with the same name as the fields, rename the controls (like add txt prefixes) and if the calculated formulas change, you know that the problem was a confused reference and you can update it.

Author Comment

by:Bill Doherty
ID: 35020687
Thanks for the info and field names aside the formulas work fine within created textboxes but now i need help with getting the results to populate into the table.

Using JayMcDo's formulas the textbox fileds [totalcost] and [groupcost] show the calculated results.

How do I get those values to populate into table fields  [totoalcost] to [tktprice] and [grouptotal] to [Bal]

or is there a way to have the system calcuate and populate the fields other than creating textbox fields on form.  

again thanks

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.


Expert Comment

ID: 35021421
I am guessing that [totalcost] and [grouptotal] fields are unbound text boxes - that is text boxes that are not linked to a table field.


If the 'unbounded textbox' assumption is correct, then why do you want an intermediate step?  Could you simply have the [tktprice] and [Bal] fields represented as bound controls (text boxes) on the form?  In this way, they would be updated and stored as you work.


Put the [tktprice] and [Bal] fields as bound text boxes on the form as well.  To avoid visual duplication, set the visible property to 'No'.  Use the same formulae for the controls as for [totalcost] and [grouptotal].


Author Comment

by:Bill Doherty
ID: 35021491

Thank you again. Your guess is correct, and I tried your suggestion first but I must be doing something wrong with the bonding. If i place the [tkprice] on the form and place the formula in the control the amount is shown but the table is not updated.  There lies my problem. I believed thats how it was done but it just isn't working for me.

Any suggestions on what I might be doing wrong?



Accepted Solution

JAMcDo earned 2000 total points
ID: 35021889
My error.  I wasn't thinking correctly about the controls for a bound object.  The bound object must be have a control identifying the table field name.

I have created a simple database based on the information that you provided - and it works providing all assumptions are correct.  (See attached file in MS Access 2010.)

The key was to add some VBA code to the AfterUpdate event for [Quantity], [ChoiceCost] and [ChFlg] controls that would update the [TkPrice] and [Bal] controls.   EETest.accdb

Expert Comment

ID: 35021920
Another thought:

In a database, it is not necessary to store calculated fields in a table.  The reasoning is that a calculation can be re-created and displayed using unbound controls on a form or report by putting a formula into the 'control' of the unbound control.


Author Closing Comment

by:Bill Doherty
ID: 35022185
Excellant Resource! great help

Author Comment

by:Bill Doherty
ID: 35022200

Thank you it worked perfectly.  

Bill d

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Suggested Courses

762 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