Saving Calculated Data in Textbox

staylor

Sapling amongst trees
Local time
Today, 13:42
Joined
Jul 3, 2008
Messages
20
Hi Everyone,

First I'd like to thank everyone for helping with other questions I've had.

My stumbling point now is that I want to save some calculated values in a form to the table it is bound to so I can print a report of the data. I know that if I put the equations in the control source of the textbox of the form, the values will display, but they will not save to the table. I've tried putting the equations in all the other events with no success. Anyone have any ideal how to accomplish my goal.

I need to save the calculated data in the fields WtPerFt,ExtWt,QtyWt,


tblExtrusionWeights: WtPerFt,ExtWt,QtyWt
frmExtrusionWeights: WtPerFt,ExtWt,QtyWt

form fields are bound to same name table fields.
 
The general rule is that you shouldn't store calculated values. You simply perform the calculation whenever you need it, such as on a report or in a query. You can simply place an unbound textbox on your report, call it Area, then as its Control Source enter the calculation, such as

=Length*Width

Or, as you showed, create a calculated field in a query,

Area:[Length]*[Width]

then base the report on the query.

Calculations in a form, report or query take way less time to perform than retrieving data from a hard disk takes.
 
Well over the weekend I have figured out a solution. Now the question is can i get it to work.

I looked at my form and saw that 3 values are saved and 3 are not. The 3 that are saved are user select/input values which have the control source bound to fields in the table. The 3 values that are not saved have the table fields bound to the texboxs which calulate the data. Now my solution is to reverse the situation and have the text boxes that calulate the values bound to the fields in the table. This brings up the hurdle of the equation can not be in the control source as it normally should be.

Question is, where do I place the equation so that it will populate the table fields like the other 3 form fields do? Is there a code option that will do this?
 
Use Missinglinq's example, I think it will be:
Code:
Sub Length_AfterUpdate
Area= Length*Width
End Sub
And
Code:
Sub Width_AfterUpdate
Area= Length*Width
End Sub

With all Area, Length, Width are both Field names and textbox names.
 
I'm not explaining my problem clearly.....

I need txtD-txtF to auto poupulate with the data from txtDD-txtFF repectively like txtA-txtC does from their respective sources. When I change the controlsource to the txtD-txtF, Anywhere I put the equations in events txtDD-txtFF they do not populate txtD-txtF. How can I over come this.

Hear's my setup...

tblA: fields A,B,C,D,E,F
frmA(bound to tblA): fields

txtA(fieldA from tblA)-Gets data from frmA.cboA(controlsource txtA)(user selection)
txtB(fieldB from tblA)-Gets data from frmA.txtBB(controlsource txtB)(user input)
txtC(fieldC from tblA)-Gets data from frmA.txtCC(controlsource txtC)(user input)
txtD(fieldD from tblA)-Needs to get data from frmA.txtDD(controlsource "equation")(calculated value)
txtE(fieldE from tblA)-Needs to get data from frmA.txtEE(controlsource "equation")(calculated value)
txtF(fieldF from tblA)-Needs to get data from frmA.txtFF(controlsource "equation")(calculated value)


Data from txtA-txtF saved in tblA
 
Last edited:

Users who are viewing this thread

Back
Top Bottom