Converting Grams to Pounds

K

KyleL

Hi all --
I'm creating a database to house birth certificate data for my job
i have two fields GramsBW (Grams Birth Weight) and LbsBW (Pounds Birth Weight)
when the GramsBW data is entered, i want it to automatically convert it to
Pounds (by multiplying by .002205) and store that data in the table, i've
tried various bits of code, listed below, but every time the calculation is
made, it rounds it to the nearest integer, and i need it to have decimal
places (i.e. 1000 grams = 2.205 pounds, but is displayed and stored as 2
pounds.

---------------------
Private Sub GramsBW_Exit(Cancel As Integer)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
---------------------
Private Sub GramsBW_Exit(Cancel As Long)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
---------------------
Private Sub GramsBW_Exit(Cancel As Double)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
 
P

Paolo

HI KileL,

Define the field bounded to the text box as double and not as long integer
as I suppose you did.

HTH Paolo
 
K

KyleL

wow, thanks a million, i feel ridiculous now >.>
another question... i just had this figured out, and i closed out of the
form without saving.. ridiculous, i know, but i have 2 dates, MothersDOB and
BabyDOB, and i need to find the MothersAge when she had the baby, i'm using
this function:
 
P

Paolo

I would do in this way. In the after update event of BDOB and in the after
update event of MDOB I would put this code

If Not IsNull(BDOB) And Not IsNull(MDOB) Then
MAGE = DateDiff("d", [MDOB], [BDOB])
End If

So if one of the two field is changed the MAGE is recalculated. Be careful
because with "d" you calculate the number of day the mother has and not the
age in years

HTH Paolo

KyleL said:
wow, thanks a million, i feel ridiculous now >.>
another question... i just had this figured out, and i closed out of the
form without saving.. ridiculous, i know, but i have 2 dates, MothersDOB and
BabyDOB, and i need to find the MothersAge when she had the baby, i'm using
this function:
----
Private Sub MDOB_Exit(Cancel As Integer)
MAge = DateDiff("d", [MDOB], [BDOB])

End Sub
---
but, it comes up with nothing


Paolo said:
HI KileL,

Define the field bounded to the text box as double and not as long integer
as I suppose you did.

HTH Paolo
 
K

KyleL

thats quite similar to the code i wrote, minus the If, then statement, which
is a good edition, however, it still fails to update the MAge field [and i
know that d is for days, it was a typo, i'm actually using "yyyy"

Paolo said:
I would do in this way. In the after update event of BDOB and in the after
update event of MDOB I would put this code

If Not IsNull(BDOB) And Not IsNull(MDOB) Then
MAGE = DateDiff("d", [MDOB], [BDOB])
End If

So if one of the two field is changed the MAGE is recalculated. Be careful
because with "d" you calculate the number of day the mother has and not the
age in years

HTH Paolo

KyleL said:
wow, thanks a million, i feel ridiculous now >.>
another question... i just had this figured out, and i closed out of the
form without saving.. ridiculous, i know, but i have 2 dates, MothersDOB and
BabyDOB, and i need to find the MothersAge when she had the baby, i'm using
this function:
----
Private Sub MDOB_Exit(Cancel As Integer)
MAge = DateDiff("d", [MDOB], [BDOB])

End Sub
---
but, it comes up with nothing


Paolo said:
HI KileL,

Define the field bounded to the text box as double and not as long integer
as I suppose you did.

HTH Paolo

:

Hi all --
I'm creating a database to house birth certificate data for my job
i have two fields GramsBW (Grams Birth Weight) and LbsBW (Pounds Birth Weight)
when the GramsBW data is entered, i want it to automatically convert it to
Pounds (by multiplying by .002205) and store that data in the table, i've
tried various bits of code, listed below, but every time the calculation is
made, it rounds it to the nearest integer, and i need it to have decimal
places (i.e. 1000 grams = 2.205 pounds, but is displayed and stored as 2
pounds.

---------------------
Private Sub GramsBW_Exit(Cancel As Integer)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
---------------------
Private Sub GramsBW_Exit(Cancel As Long)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
---------------------
Private Sub GramsBW_Exit(Cancel As Double)
LbsBW = (GramsBW) * (0.002205)

End Sub
---------------------
 

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