Solved

MS Access Calculated form fileds

Posted on 2011-03-01
9
348 Views
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.

thanks
0
Comment
Question by:mwpai
[X]
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
9 Comments
 
LVL 3

Expert Comment

by:JAMcDo
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]

J.
0
 
LVL 22

Expert Comment

by:rspahitz
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.
0
 

Author Comment

by:mwpai
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

0
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!

 
LVL 3

Expert Comment

by:JAMcDo
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.

Question:

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.

Alternative:

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

J.
0
 

Author Comment

by:mwpai
ID: 35021491
JAMcDo,

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?

thanks

Billd
0
 
LVL 3

Accepted Solution

by:
JAMcDo earned 500 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
0
 
LVL 3

Expert Comment

by:JAMcDo
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.

J.
0
 

Author Closing Comment

by:mwpai
ID: 35022185
Excellant Resource! great help
0
 

Author Comment

by:mwpai
ID: 35022200
JAMcDo,

Thank you it worked perfectly.  

Bill d
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

749 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