Solved

MS Access Calculated form fileds

Posted on 2011-03-01
9
335 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

773 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