Inacurrate calculation in a formula (1 Viewer)

snermin

New member
Local time
Today, 05:48
Joined
Nov 9, 2008
Messages
3
OK, I am newbie to Access. I did however managed to create several simple DBs, but I am now stuck with this problem. I am making a rather complex database that needs to have a sort of calculator within.
There is a medical formula for a something called MELD score. The original formula is:

MELD Score = 0.957 x Ln(creatinine mg/dL)
+ 0.378 x Ln(bilirubin mg/dL)
+ 1.120 x Ln(INR)
+ 0.643

I know that VBA function Log actually is Ln math function. So here is how I set up the scene. I created a simple table that has creatinine, bilirubin, INR and of course MELD field. I also created a query for a table and a form linked to that query. The form is designed in that way that when you click on MELD field you automatically get a calculated MELD value. Here is the code:

Private Sub MELD_Click()

Dim LnCrea
LnCrea = Log([Kreatinin] / 88.4)

Dim LnTbil
LnTbil = Log([Bilirubin] / 17.1)

Dim LnINR
LnINR = Log([INR])

[MELD] = (9.57 * LnCrea) + (3.78 * LnTbil) + (11.2 * LnINR) + 6.43

End Sub

Note that entered values of creatinin are in different units, so a conversion must be performed (Creatinin/88.4 etc) before entering into formula. Now, everything works as it should, except I am getting wrong result at the end (since I have the same calculator in Excel which is confirmed to work OK).
What am I doing wrong? I've lost entire weekend starring into this code and trying different thing - but without success. TNX in advance

Nermin
 

Rabbie

Super Moderator
Local time
Today, 04:48
Joined
Jul 10, 2007
Messages
5,906
Can you post the values you are inputting, the result youa re getting andt he result you should be getting? Also can you post the Excel Formula.
 

snermin

New member
Local time
Today, 05:48
Joined
Nov 9, 2008
Messages
3
Thank you for your time. Here is the Excel file.
In Excel the final result is 11, while in my Access file it is 5 (data is already entered in Excel file).
TNX again.
 

Attachments

  • MELD_calc.xls
    21 KB · Views: 756

Kiwiman

Registered User
Local time
Today, 04:48
Joined
Apr 27, 2008
Messages
799
Howzit

I used the below and got your 11.099 that is in your excel sheet. Didn't change anything except referenced the current record using me.xxx

See attached example...

Code:
Private Sub MELDCalc_Click()
'Stop


Dim LnCrea
LnCrea = Log(Me.Creatinine / 88.4)
Debug.Print LnCrea

Dim LnTbil
LnTbil = Log(Me.Bilirubin / 17.1)
Debug.Print LnTbil

Dim LnINR
LnINR = Log(Me.INR)
Debug.Print LnINR


Me.MELD = (9.57 * LnCrea) + (3.78 * LnTbil) + (11.2 * LnINR) + 6.43

Debug.Print Me.MELD

End Sub
 

Attachments

  • MELD.zip
    45 KB · Views: 544
Last edited:

Users who are viewing this thread

Top Bottom