Structured Conditional Statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Am having trouble with the correct syntax for "If...Then" and "Select Case" statements. Am not using correct punctuation somewhere. Example: Select Case [Usage] Case Is <=0 (0) Case Is >=90 (90) Case Else [Usage]. Any suggestions?
 
Select Case [Usage]
Case Is <=0
'{statements}

Case Is >=90
'{statements}

Case Else
'{statements}
End Select

HTH
Van T. Dinh
MVP (Access)


-----Original Message-----
Am having trouble with the correct syntax
for "If...Then" and "Select Case" statements. Am not
using correct punctuation somewhere. Example: Select Case
[Usage] Case Is said:
 
Am having trouble with the correct syntax for "If...Then" and "Select Case" statements. Am not using correct punctuation somewhere. Example: Select Case [Usage] Case Is <=0 (0) Case Is >=90 (90) Case Else [Usage]. Any suggestions?

In VBA it's all on separate lines:

Select Case [Usage]
Case Is <=0
answer = 0
Case Is >=90
answer = 90
Case Else
answer = [Usage]
End Select

If you're talking about using CASE in a Query, unfortunately it is not
supported in the Access dialect of SQL. Neither is If... Then. You can
use the IIF() or Switch() VBA functions - in a query, you could use

Answer: Switch([Usage] <= 0, 0, [Usage] >= 90, 90, True, [Usage])
 
alternatives to the IIF function in a query are SWITCH, CHOOSE, and User Defined functions.

example: SWITCH( [usage]<=0,0, [usage]>=90,90, TRUE,[usage])

(david)
 
Back
Top