Access 2003 VBA LostFocus Problem

Hello, I'm using the following code to calculate price based on QTY * Price. My code works unless the user types in a value like 1.5. It appears to be rounding the value up to 2.

What am I doing wrong?

Private Sub txt_RFR_QTY1_LostFocus()
'first ensure QTY is not null and assign value
Dim myQTY As Double

If Me.txt_RFR_QTY1.Text = "" Then
Me.txt_RFR_QTY1.Text = 0
myQTY = Me.txt_RFR_QTY1.Text
myQTY = Me.txt_RFR_QTY1.Text

End If

'get and calculate price
 Dim qdf As QueryDef
 Dim rst As Recordset
 Dim myPrice As Currency

 Set qdf = CurrentDb.QueryDefs("Get_PartPrice")

 qdf.Parameters(0) = Me.cbo_RFR_PartNumber1.Column(0)
 qdf.Parameters(1) = Me.cbo_RFR_PartNumber1.Column(0)

 Set rst = qdf.OpenRecordset

For Each fld In rst.Fields
Me.txt_RFR_PartCost1.Visible = True
      myPrice = fld
      Dim TotalPrice As Currency
      TotalPrice = (myPrice * myQTY)
     Me.txt_RFR_PartCost1.Text = TotalPrice
 Me.txt_RFR_PartCost1.Visible = False
 Set rst = Nothing
 Set qdf = Nothing
End Sub

Open in new window

Who is Participating?
mbizupConnect With a Mentor Commented:
Check the design of the underlying table(s)...

These fields should be numeric, and under the field properties in the bottom panel in the table design view, set the Field Length to Double
gogetsomeAuthor Commented:
Exactly! Thank you so much!!! I might pick up access vba one day soon.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.