if statement
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

If Statement

resolvedResolved · High Priority · Version 2003

replyReply Fri 13 Mar 2009, 16:27Delegate Jonathan said...

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

For upcoming training course dates see: Pricing & availability

replyReply Mon 20 Apr 2009, 09:42Trainer Anthony said...

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.

 

Please browse our web site to find out more about
ms-access-course and other Microsoft training courses.

Access tip:

Changing MS Programs Text Size

A handy way to increase or decrease the size of text in Microsoft Word, Microsoft PowerPoint, Microsoft FrontPage, or Microsoft Publisher, first, select the text you want to resize.

Then, to increase the font size, press CTRL+SHIFT+>.

To decrease the font size, press CTRL+SHIFT+<.

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard