Solved

MS Access Calculated form fileds

Posted on 2011-03-01
9
313 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

by:JAMcDo
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mwpai
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Excellant Resource! great help
0
 

Author Comment

by:mwpai
Comment Utility
JAMcDo,

Thank you it worked perfectly.  

Bill d
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now