converting pounds and ounces to kilograms

  • Thread starter Mark M Simonian
  • Start date
M

Mark M Simonian

I have a form that tracks a newborn's weight in Access 2002. Could I get
suggestions about how best to create my fields so I can do a calculated
conversion. Traditionally the nursey will log it as pounds and ounces so do
I write two fields with pounds then ounces? If I do that how would I create
the third field that calculates the kilograms? If I put just pounds then the
conversion would be easy but I need the ounces so with two fields I am lost.

Some how Google can do it by saying how many kilograms in 6 pounds 8 ounces.
Is there an easy way to do this or am I way above my head on programming
this?

Any help appreciated.
-----------------------------------------------------
Mark M Simonian MD
Medical Director, ChildNet Medical Assoc.
681 Medical Center Drive West #106
Clovis, CA 93611
(559) 325-6850
(e-mail address removed)
****************************************
Alert: This email and any files transmitted with it
are intended solely for the use of the individual or
entity to whom they are addressed and may contain
confidential, patient health or other legally
privileged information. If you have received this
email in error please notify the sender by email,
delete and destroy this message and its attachments.
Any unauthorized review, use, disclosure,
or distribution is prohibited.
 
K

Ken Snell

Yes, use two textboxes to capture the pounds and ounces separately. Then use
an expression similar to this as the control source of the third textbox to
convert to kilograms (assuming that you are not going to store the kilograms
amount in a table through having this third textbox bound to a field in the
form's record source):

=(Nz([textbox1], 0) + Nz([textbox2], 0)/16)/2.2

(assuming you want to use the conversion factor of 1 kg = 2.2 lbs).

If you want to bind the third textbox to a field so that you can store it in
a table, then put this code on the AfterUpdate event of each of the first
two textboxes (example is shown for textbox1):

Private Sub textbox1_AfterUpdate()
Me.textbox3.Value = (Nz(Me.textbox1, 0) + Nz(Me.textbox2, 0) / 16) / 2.2
End Sub
 
K

Kevin Sprinkel

-----Original Message-----
I have a form that tracks a newborn's weight in Access 2002. Could I get
suggestions about how best to create my fields so I can do a calculated
conversion. Traditionally the nursey will log it as pounds and ounces so do
I write two fields with pounds then ounces? If I do that how would I create
the third field that calculates the kilograms? If I put just pounds then the
conversion would be easy but I need the ounces so with
two fields I am lost.

Hi, Mark.

One principle I continually use in designing databases is
to ask for data from users the way they understand it, and
let the computer do the hard work. So, since the Nursing
staff uses pounds and ounces, I think that makes the most
sense.

I suggest using two fields. Pounds can be an integer
field, but I suggest making Ounces a single precision
number if you wish to enter decimals of an ounce.

Re: this third field which would calculate the weight in
kilograms: storing calculations is discussed here daily.
In general, DON'T do it; it's faster to calculate on the
fly, it wastes disk space, and you risk data integrity if
someone changes data in the table through anything other
than your form.

So, by all means *display* your calculation in an unbound
control on your form, and calculate it in a query if you
need to print it on a report, etc.

So, with form controls txtLB and txtOZ bound to say, LB
and OZ fields, place the following expression in your
txtKG control's Control Source property to display the
result in kilograms:

= [txtLB]*.4535924 + [txtOZ]*[.02834952]

The syntax for a query calculation adds a name for the
calculated 'field' and a colon before the expression:

[KG]:[txtLB]*.4535924 + [txtOZ]*[.02834952]

KG will then available to a report like any other field.

HTH
Kevin Sprinkel
 
J

John Nurick

Hi Mark,

I get the impression you want to store the weight in kilos but allow the
nurse to enter it either way. That's the way I'd be inclined to do it.

There are two main ways to go, depending on the user interface you want.
One is to use one textbox on your form with code behind it to interpret
whether the value that's entered is lb and oz or kg (or even g). The
other is to have three textboxes - one each for lb, oz and kg and update
the third based on what's typed in the first two.

The first is neater (I feel) but means more complicated programming. If
you want to go that way, post back here and we'll work it out. For the
other, create the three textboxes on the form. Let's call them txtKG,
txtLB and txtOZ. Bind txtKG to the relevant column in your table (which
I'm assuming is of type Single) but leave the other two unbound.

Now you need to set up the BeforeUpdate event procedures of txtLB and
txtOZ to first check that the values that are entered are acceptable
and (if they are) to calculate the value in kilos and insert it into
txtKG.

The code in txtOZ_BeforeUpdate() will be something like this:

Dim sngOZ As Single
Dim sngKG As Single

'Value must be numeric
If IsNumeric(Me.txtOZ.Value) Then
sngOZ = CSng(Me.txtOZ.Value)
'Value must be between 0 and 16
If sngOZ < 0 Then Cancel = True
If sngOZ >= 16 Then Cancel = True
Else 'not numeric
Cancel = True
End If

If Cancel <> True Then
'calculate and update
sngKG = (CSng(Nz(Me.txtLB.Value),0) + sngOZ / 16) / 2.2031284
Me.txtKG.Value = Round(sngKG, 3)
Else
MsgBox "Please enter the number of ounces (0 to less than 16)"
End If

and that in txtLB_BeforeUpdate() will be pretty similar apart from the
different data validation rules.

You'll also need to put code in the form's Current event procedure to
clear txtLB and txtOZ, e.g.
Me.txtLB.Value = Null
Or you could even load the textboxes with the pounds and ounces, using
something like

Dim sngKG As Single

sngKG = Nz(Me.txtKG.Value,0)
Me.txtLB.Value = Fix(sngKG * 2.2031284)
Me.txtOZ.Value = (sngKG * 2.2031284 - CInt(Me.txtLB.Value)) * 16
 
M

Mark M Simonian

Wow, Tremendous ideas. It sounds like this is something that other people
find thought about already. I appreciate the specific examples because the
programming is a step beyond me but with the examples I think I can plug it
in. Thanks a bunch!

-----------------------------------------------------
Mark M Simonian MD
Medical Director, ChildNet Medical Assoc.
681 Medical Center Drive West #106
Clovis, CA 93611
(559) 325-6850
(e-mail address removed)
****************************************
Alert: This email and any files transmitted with it
are intended solely for the use of the individual or
entity to whom they are addressed and may contain
confidential, patient health or other legally
privileged information. If you have received this
email in error please notify the sender by email,
delete and destroy this message and its attachments.
Any unauthorized review, use, disclosure,
or distribution is prohibited.
 

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