gogetsome
asked on
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?
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.SetFocus
Me.txt_RFR_QTY1.Text = 0
myQTY = Me.txt_RFR_QTY1.Text
Screen.PreviousControl.SetFocus
Else
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
Me.txt_RFR_PartCost1.SetFocus
myPrice = fld
Dim TotalPrice As Currency
TotalPrice = (myPrice * myQTY)
Me.txt_RFR_PartCost1.Text = TotalPrice
Screen.PreviousControl.SetFocus
Me.txt_RFR_PartCost1.Visible = False
Next
rst.Close
qdf.Close
Set rst = Nothing
Set qdf = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER