Calculated Fields

G

Guest

I have created a purchase order subform that has a quantity field, a unit
price field and a total price field. I would like to be able to enter a unit
price and haven access calculate the total price. In the same token I would
like to be able to enter a total price and and have access calculate the unit
price. These values will need to be saved in the underlying table.
 
G

Guest

You could use a bit of code in your field_AfterUpdate events to recalculate
the other textboxes. You will also need to tell between "user" updates and
your "auto" updates for those fields. Normally you will have to declare a
form level boolean variable to flag whether you are within an "auto" update.
Something like the following:

Private m_InsideAutoUpdate As Boolean

Private Sub txtUnitPrice_AfterUpdate()
If Not m_InsideAutoUpdate Then
m_InsideAutoUpdate = True
txtTotalPrice = txtUnitPrice * txtUnits
m_InsideAutoUpdate = False
End If
End Sub

You will need to put the symmetrical code in the TotalPrice AfterUpdate
event. Also before updating the other textbox you may need to check for
validity (unless you bind the textboxes to the table to enable Access to
validate it for you). I do not have an Access here to check the code, but it
must be pretty close.

Hope this helps
 

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