mmerrill
05-09-2001, 11:13 PM
Hi I'm somewhat new to Access and I'm using Access 97. My problem is I want to calculate
a entered number in 2 fields and have the
answer show up on the form ie:
dry .2252 + wet .3352 = total
dry,wet and total are currently my fields
I understand I have to enter the calculation
in the total field my problem is "where" do
I enter the calculation? Please help.
Thanks you in advance
Mike
KevinM
05-10-2001, 12:55 AM
First of all remove the [Total] field from the table, form reports etc. You don't need to store this value in a table.
Create a query based on your table and add this expression in a new column....
Total:[dry]+[wet]
That's all there is to is it. Base your form on this query to view this Total.
TIP: if you use a continous form, you can add a Grand Total in the form footer. Add a textbox and in the controlsource put....
=Sum([Total])
HTH
Pat Hartman
05-10-2001, 04:28 PM
If you can change the values for dry and wet on the form, you need to calculate the total on the form rather than in the query so it will be current. You will need to do this in several places:
Me.txtTotal = Nz(Me.txtDry,0) + Nz(Me.Wet,0)
Put the code in the following events:
OnCurrent for the form
AfterUpdate for the Dry control
AfterUpdate for the Wet control
KevinM
05-11-2001, 01:26 AM
I still think it would be better in a query, especially if you want the total on a record by record basis.
You would then have access to these totals in other forms and reports.
Depends on the size of the recordset Kev. The biggest improvement gained when using queries is to remove calculated expressions from them. If mmerrill wanted to use a query then the form should be based on the query, taking Pat's suggestion further I would only put the code in the On Current event and in the after update of both dry and wet just put Form_Current, as to which is the best method, contentious to say the least.
KevinM
05-11-2001, 12:38 PM
Good point Rich.
Although if you wanted to show a grand total of an expression in the form then I think you can only do this in a query.
Pat Hartman
05-11-2001, 08:32 PM
If you don't also put the code in the AfterUpdate events of the fields, the total will remain as it was when the record became current. This could be confusing.
Although we are only talking about a single line of code, it could be put into a subroutine and called from three places.