Jonathan has attended:
Access Introduction course
Access Intermediate course
Access Advanced course
If Statement
Hi Everyone,
Public Function S2Org(DateVariable As Date, AgentID As Integer, Doc As Double)
Dim cost As Currency
If DateVariable <= #3/31/2009# And AgentID <> 355 Then
cost = CCur(Doc * 19.45)
ElseIf DateVariable <= #3/31/2009# And AgentID = 355 Then
cost = CCur(Doc * 24.75)
End If
Is there by any chance i could have
If DateVariable <= #3/31/2009# And AgentID <> 355 And AgentID <>356 Then
cost = CCur(Doc * 19.45)
Please advise
RE: If Statement
Hi Jonathan. There are a number of ways to achieve this. You could use nested IF statements, or concatenate AND statements but this can get difficult to follow and debug. Alternatively, you could set the value of a new reference variable dependent on each IF statement as so:
If DateVariable <= #3/31/2009# And AgentID <> 355 Then
scenario1 = TRUE
Once set you can use the scenario1 variable in further IF statements:
If scenario1 = TRUE AND AgentID <>356 Then
cost = CCur(Doc * 19.45)
...and so on! You could also use the CASE statement to make the code more explicit.
Hope this helps,
Anthony