Function Problem

kryten

Registered User.
Local time
Yesterday, 19:51
Joined
Jul 24, 2004
Messages
40
Hi everyone,

I have the following function:

Private Function TradeShippingCalc()
If [OrderSubtotal] >= 86 Then
[Shipping] = 0
Else: Me![Shipping] = 5
End If
End Function

When I call this function -
Private Sub TradeOrderSubform_Exit(Cancel As Integer)
Call TradeShippingCalc
End Sub

It only returns the Else: part of the code, no matter what value is in the [OrderSubtotal] the [Shipping] = 5

Any help would be greatly appreciated!
 
Private Function TradeShippingCalc()
If me![OrderSubtotal] >= 86 Then
me![Shipping] = 0
Else: Me![Shipping] = 5
End If
End Function

???
kh
 
Problem continues

Hi Ken,

Tried that, same result.
 
Why are you using a function if you are not returning a value?

What's OrderTotal?
Why are you using ! when . is better in this situation?
 
SJ McAbney said:
Why are you using a function if you are not returning a value?

What's OrderTotal?
Why are you using ! when . is better in this situation?

Hi,

I don't understand, I am trying to return a value of either £0.00 or £5.00 in the [Shipping] field.

How else should I do it?
 
Your code should all fit in the exit event...

kh
 
Is this your first function using vba?

kh
 
Hi Ken,

Yes it is (can't you tell!).

I deleted the function and just put the code in the Subform_Exit, this works only intermittently. Do I need to put the code somewhere else?

Thanks for your help.
 
Code:
Private Function TradeShippingCalc(ByVal intSubtotal As Integer)
    If Me.OrderSubtotal >= 86 Then
        TradeShippingCalc = 0
    Else
        TradeShippingCalc = 5
    End If
End Function

In VBA:
Me.Shipping =TradeShippingCalc(Me.OrderSubtotal)

In a query:
Shipping: TradeShippingCalc([OrderSubtotal])

In a form:
=TradeShippingCalc([OrderSubtotal])
 
What does the ByVal do?

kh

---- Never mind, there's a good explanation in Help.
 
Last edited:
SJ McAbney said:
Code:
Private Function TradeShippingCalc(ByVal intSubtotal As Integer)
    If Me.OrderSubtotal >= 86 Then
        TradeShippingCalc = 0
    Else
        TradeShippingCalc = 5
    End If
End Function

In VBA:
Me.Shipping =TradeShippingCalc(Me.OrderSubtotal)

In a query:
Shipping: TradeShippingCalc([OrderSubtotal])

In a form:
=TradeShippingCalc([OrderSubtotal])

Thank you! I used the code in the control source of the [shipping] field, this works a treat.
 

Users who are viewing this thread

Back
Top Bottom