Please tell me what wrong with this code?

Vu_Ho

Registered User.
Local time
Today, 11:40
Joined
Aug 19, 2013
Messages
20
This is what I put under the AfterUpdate property of a field named [Order_Type] which has three types: Regular, Urgent and Very Urgent; whereas when it comes to Urgent, then customer would have to pay a fee of $20 and the return date would be Date()+1; like wise with Very Urgent.
Private Sub Order_Type_AfterUpdate()
If [Order_Type] = "Urgent" Then
Me.Total = Round(Me.Total + 20)
If [Order_Type] = "Very Urgent" Then
Me.Total = Round(Me.Total + 30)
End If
End Sub
Please correct my code above. Not sure what's wrong with that. Thanks a bunch
 
Code:
Private Sub Order_Type_AfterUpdate()

           If [Order_Type] = "Urgent" Then Me.Total = Round(Me.Total + 20)
    
           If [Order_Type] = "Very Urgent" Then Me.Total = Round(Me.Total + 30)
    
End Sub
 
Try a Select Case statement..
Code:
Private Sub Order_Type_AfterUpdate()
    Select Case [Order_Type]
        Case "Urgent" 
            Me.Total = Round(Me.Total + 20)
        Case "Very Urgent"
            Me.Total = Round(Me.Total + 30)
    End Select
End Sub
EDIT: Blimey, looks like everyone is on this case.. :D
 
Guys, there is still a problem:
Actually I have 4 fields:
1. [Order_Type] with 3 types: Regular, Urgent, Very Urgent;
2. [Quantity];
3. [Product_Price], which is locked (don't want users change this); and
4. [Total]
I want whenever the Order_Type = Urgent or Very Urgent, then Total would be: Quantity*20+Quantity*Product_Price. Then I put the codes like this:
Private Sub Order_Type_AfterUpdate()
Select Case [Order_Type]
Case "Urgent"
Me.Total = Round(Me.Quantity * 20 + Quantity * Product_Price)
Case "Very Urgent"
Me.Total = Round(Me.Quantity * 30 + Quantity * Product_Price)
End Select
End Sub.
But there are 2 following issues:
1. Nothing happens with Total >:<
2. If someone comes back and correct values in Order_Type from Urgent to Regular, I got an error message like err! in the customer field! and the records are not updated!
What's wrong? :banghead:
 
1. Nothing happens with Total >:<
Sounds to me like you are trying to Save a Calculated Value.. Why are you doing this? Calculate values belong in Queries not tables..

To answer this..
2. If someone comes back and correct values in Order_Type from Urgent to Regular, I got an error message like err! in the customer field! and the records are not updated!
What's wrong? :banghead:
You need to answer TJ's question..
What is wrong with your code? What errors are you getting?
 
Oh I got it, my mistake! I put the calculation in the query instead of on the form. Another question is how about the date? I put this this way:
Private Sub Order_Type_AfterUpdate()
Select Case [Order_Type]
Case "Urgent"
Me.Total = Round(Me.Quantity * 20 + Quantity * Product_Price)
Me.OrderReturnDate=Round(Me.OrderDate+2)
Case "Very Urgent"
Me.Total = Round(Me.Quantity * 30 + Quantity * Product_Price)
Me.OrderReturnDate=Round(Me.OrderDate+1)
End Select
End Sub
Anything wrong with these code?
 
maybe this is looking too broadly, but your first bit of code contains two IFs and only one End If.
 
Actually I am trying to do something like If Order type = Urgent, then the Orderreturndate=Date()+2.
 

Users who are viewing this thread

Back
Top Bottom