Share via

Creating BMI using microsoft access VBA...

Anonymous
2015-02-16T09:18:56+00:00

Hello all,

Please can some help me out am trying to write a bmi code in microsoft access vba. below code is what i wrote,

Option Compare Database

Private Sub btncalculate_Click()

Dim Weight, height, bmi, x As Single

Weight = Text0.Text

height = Text2.Text

bmi = (Weight) / height ^ 2

Text5.Text = Round(bmi, 1)

If bmi <= 15 Then

Text5.Text = "Under weight"

Else bmi > 15  bmi <= 25 Then (but am recieving red colour here which means there is error)

Text5.Text = "Optimum Weight"

Else

Text5.Text = "Over weight"

End If

End Sub

please i need a help on this. Thanks to you all.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2015-02-17T07:35:31+00:00

    Hello ciao! Sandro , Sandro Peruz and to every one in the house,

    I just want to thank you guyz for making things easy for every one in this forum, may God bless you all. i am at the end of my project but where i am finding difficulties is this...... i have a switch board on this switchboard i create access level where i have The Doctor, nurse, ****,Lab.  so the issue here is that i want the doctor to have access to all the button on the switch board, then the nurse to record button, the **** to the **** button, while the lab operation o the lab button, please i don't mind if you can help me out with examples and put it on one drive.com i will really appreciate it beacause this project has been given me a sleepless nite. find below the screen shot!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-02-16T14:19:25+00:00

    ciao,

    just a little example here for you:

    http://1drv.ms/1xqxyp9 BMI demo.

    Private Sub cmdCalculate_Click()

    'Dim Weight As Single, height As Single, bmi As Single, x As Single

      'Weight = Me.Text0

      'height = Me.Text2

      'bmi = (Weight) / height ^ 2

      Me.txtBmi = Round(Me.txtWeight / (Me.txtHeight ^ 2), 1)

    ' Me.Text5 = Round(bmi, 1)

      Select Case Me.txtBmi

         Case 0 To 15

             MsgBox "you have to eat, eat and eat..!"

         Case 14 To 25

            MsgBox "you are good"

         Case Else

             MsgBox "you are bad"

      End Select

    End Sub

    let us know.

    ciao! Sandro.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-02-16T13:44:50+00:00

    Hello ciao Sandro and Sandro Peruz,

    Thanks for your quick response i really appreciate. i added the code the way you guys fix it but once i triggerd the buton it keeps on giving me "overt" any number i keyed in is just overt and its not suppose to work like the see below diagram may be you can help out.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-02-16T10:45:05+00:00

    ...

    just a little amendment...

    Dim Weight As Single, height As Single, bmi As Single, x As Single

     Weight = Me.Text0

     height = Me.Text2

     bmi = (Weight) / height ^ 2

    me.Text5= Round(bmi, 1)

     Select Case bmi

        Case 15

            MsgBox "ok"

        Case bmi > 15 And bmi <= 25

            MsgBox "nornal"

        Case Else

            MsgBox "overt"

     End Select

    ciao, Sandro

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2015-02-16T10:40:38+00:00

    hi,

    try in this way:

     Dim Weight As Single, height As Single, bmi As Single, x As Single

     Weight = Me.Text0

     height = Me.Text2

     bmi = (Weight) / height ^ 2

     Text5.Text = Round(bmi, 1)

     Select Case bmi

        Case 15

            MsgBox "ok"

        Case bmi > 15 And bmi <= 25

            MsgBox "nornal"

        Case Else

            MsgBox "overt"

     End Select

    ciao, Sandro.

    Was this answer helpful?

    0 comments No comments