Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

if statement

ResolvedVersion 2003

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

Mon 27 Apr 2009: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Hide Access Tables

One method of stopping your Access tables appearing in Database window, is to rename the table(s) with the prefix usys.

This converts the table into a system object, which cannot be viewed in the Database window.

You can show system objects in the Database window by the following:

Step 1: On the Tools menu, click Options.
Step 2: Click the View tab.
Under Show, select the System Objects check box.
Click OK.

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.