Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong with If Then Else Statement

Status
Not open for further replies.

james33

Technical User
Dec 23, 2000
1,345
IE
Dear All,
Please could you tell me what is wrong with the following statement:

Code:
Private Sub PartsCostExVAT_AfterUpdate()
    
If Me![LabourCost] / Me![PartsCostExVAT] > 2 Then VatRate = 12.50
    
ElseIf Me![LabourCost] / Me![PartsCostExVAT] < 2 Then VatRate = 21.00
            
End If
End Sub

I type it in as above but the 21.00 turns into 21# immediately after I go to the next line.
The 3 Fields are formatted as Number|Fixed|2 Decimal places

Thank you in advance for any help
Regards Jim :cool:
 
Thanks JohnYingling,

But the Code isn't setting the value of the fields in the Form according to the conditions, would you please tell me where I am going wrong?

Regards Jim
 
james33,
You need to set your format to General Number. DOnt worry about the decimal palcement..

:)
 
Hey james33,
just a quick update... instead of setting the format to fixed set it to General number...


:)
 
Thanks all for your suggestions,
I realised that I had to set all formats to the same but I chose Standard and 2 Decimal places and then it worked but I guess as Love Tech says I should really set them all back to General Number and leave Decimals as auto.
And I take your point TekTipCensorsFreeSpe and will act accordingly
Here is it working now:

Code:
Private Sub PartsCostExVAT_LostFocus()

    If (Me![LabourCost] / Me![PartsCostExVAT]) > 2 Then
    [VatRate] = &quot;12.50&quot;
    ElseIf (Me![LabourCost] / Me![PartsCostExVAT]) < 2 Then [VatRate] = &quot;21.00&quot;
End If

End Sub

It changes the Vat Rate after checking how much of the overall price is made up of the Labour component
However, the following unfortunately insists on rounding the Labour down to the next whole number. (All fields are formatted as Standard and 2 decimal places)

Code:
Private Sub RepairTime_AfterUpdate()

        Me![LabourCost] = ((Me![RepairTime]) * (Me![EmployeeRatePerHour]))

End Sub

The format seems to be the trouble!
I am just getting that exciting feeling that with the right knowledge and luck somethings may actually work (sometimes).
I will probably be back for more
Thank you all again
Jim
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top