update a table from a form text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I wanted to have a text box in a form that can do a simple calculation. So I added a text box and typed in my expression to do the subtraction. That works fine.
However, I would like the new information to be saved to the same table that the rest of the form is being saved to.
There is no VBA code or macro that does the saving, although all the records are being placed in the table.

The question is, how can I get the table to recognize the new text box that does calculations?

Thank you
 
Roger, would you consider it wrong if the calcuated field was ever *not* the
same as the subtraction expression? If so, you must not store this field in
your table.

Instead, use a query to generate the calculated field. Type an expression
such as this into the Field row of the query design grid:
Diff: [Credit] - [Debit]
This generates a field named "Diff". By setting the RecordSource of your
form or report to this query, you have the calculated field available where
ever you want. It can never be wrong, and you have no maintenance worries.

If you want to store the field in the table anyway and you understand the
maintenance issues you are creating for yourself, use the AfterUpdate event
procedure of the controls involved in the calcuations. This example assumes
you have table fields named Credit, Debit, and Diff.

Private Sub Credit_AfterUpdate()
Me.[Diff] = Me.[Credit] - Me.[Debit]
End Sub

Private Sub Debit_AfterUpdate()
Call Sub Credit_AfterUpdate
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Roger said:
I wanted to have a text box in a form that can do a simple calculation.
So I added a text box and typed in my expression to do the subtraction.
That works fine.
However, I would like the new information to be saved to the same table
that the rest of the form is being saved to.
There is no VBA code or macro that does the saving, although all the
records are being placed in the table.
 
Back
Top