MS Access Calculated form fileds

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.

Bill DohertyNetwork AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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]

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.
Bill DohertyNetwork AdministratorAuthor Commented:
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

The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

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].

Bill DohertyNetwork AdministratorAuthor Commented:

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?


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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

Bill DohertyNetwork AdministratorAuthor Commented:
Excellant Resource! great help
Bill DohertyNetwork AdministratorAuthor Commented:

Thank you it worked perfectly.  

Bill d
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.