if statement

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

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » If Statement

If Statement

resolvedResolved · High Priority · Version 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:

Relationship maps

It is important to create proper relationships between tables. You can use Access to help check your designs and evaluate them by printing them in graphical format to help with design purposes


Click on the Tools menu, click Relationships.
On the File menu, click Print Relationships. View or print as required

View all Access hints and tips


Server loaded in 0.07 secs.