View Full Version : Expressions in a form


BTKS
06-07-2000, 09:46 AM
I would like to know why when you put a formula or expression in a form's control, it doesn't save it to the table. Is there a way to do this? It seems pointless to have expressions in the form if you can't build reports off of them?

Travis
06-07-2000, 12:02 PM
First by making the control source of a text box a formula you are not specifing a field to save the data to.

In order to save the value you would have to set the fields value = to the calculation.

I recommend the following.

add this code to the Form AfterUpdate Event

Private Sub Form_AfterUpdate()
me![FieldName] = me![CalculationField]
End Sub

Just as a note (in which I don't think I will find many programmers who will disagree with me on this.) you don't want to as a rule store a calculation. Calculations should not be static as the data could be changing. You will then need to add the Calculation to the Report if you want to see it there also.

Pat Hartman
06-07-2000, 05:29 PM
Travis, I think you mean the Form BeforeUPdate event. The AfterUpdate event fires AFTER the record is saved. Code that dirties the current record in this event (as your suggestion does) will put Access into a loop, causing some strange effects.