View Single Post
  #2  
Old December 20th, 2006, 07:40 PM posted to microsoft.public.access.forms
John Vinson
external usenet poster
 
Posts: 4,033
Default calculations in form

On Wed, 20 Dec 2006 08:45:02 -0800, rs30
wrote:

I have a form for users to enter data. I would like users to be able to
enter data on height and weight in either (cm) or (in) and (kg) or (lbs) but
only store the data in my table in metric. Tips?


One way would be to use three controls for each such field: an unbound
textbox for the user entry; an Option Group control with the units
(say Kilograms, Pounds, Stones, as 1, 2, 3), and a textbox (which
might be invisible) bound to the metric table field.

You could have code in the AfterUpdate event of the unbound data entry
textbox to read the unit control and make the appropriate calculation,
e.g.

Private Sub txtEnterWeight_AfterUpdate()
Select Case Me.optUnits
Case 1 ' kilograms, just pass the value
Me.txtWeight = Me.txtEnterWeight
Case 2 ' pounds
Me.txtWeight = Me.txtEnterWeight * 2.2046
Case 3 ' stones
Me.txtWeight = Me.txtEnterWeight * 0.15747
End Select
End Sub

You'll want code going the other way (filling the txtEnterWeight
textbox by converting from kilograms to the other unit) in *both* the
form's Current event and the option group's AfterUpdate event.

John W. Vinson[MVP]