Calculated Field

B

Bryan

How do I assign a calculated field to a table field?

My "Control Source" is set to =([Forms]![payables]!
[addpayablecategory].[Form]![subtotal])

Now, how do I assign this calculated value to the "total"
field in my table?
 
W

Wayne Morgan

The recommended procedure is Don't. If the value is something you can
calculate, then calculate it when you need it. Don't store data you don't
need to. If for some reason you just have to do it then create a hidden
textbox on the form and bind it to the field. In the BeforeUpdate event of
the form, set the value of this hidden textbox to the calculated value.
 
B

bryan

I need the value store for later reference and
comparison. I don't understand what the BeforeUpdate
parameter you're recommending. Are u saying open the
form, and in the properties of the form, set the value of
the hidden textbox to the calculated value?
-----Original Message-----
The recommended procedure is Don't. If the value is something you can
calculate, then calculate it when you need it. Don't store data you don't
need to. If for some reason you just have to do it then create a hidden
textbox on the form and bind it to the field. In the BeforeUpdate event of
the form, set the value of this hidden textbox to the calculated value.

--
Wayne Morgan
Microsoft Access MVP


Bryan said:
How do I assign a calculated field to a table field?

My "Control Source" is set to =([Forms]![payables]!
[addpayablecategory].[Form]![subtotal])

Now, how do I assign this calculated value to the "total"
field in my table?


.
 
W

Wayne Morgan

No, on the Event tab for the Form's properties, set the BeforeUpdate event
to [Event Procedure] and click the ... button. This wil open the VBA editor
and create the framework for the BeforeUpdate event of the form. Between the
Private Sub Form_BeforeUpdate and the End Sub place the code that will set
the value of this hidden text box to the value you want. The textbox should
be bound to the field you want to store the value in. The Form's
BeforeUpdate event runs just before the form saves the data to the tables,
so you'll be putting the data in the control just in time, but after the
user would be able to make changes.

I realize that you are wanting the value for later comparison, but you
should be able to compare against the calculation as well, not just against
a value in a field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top