IIf Syntax

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

Can this be done?

If CDSub = 2 or 3 Then
MsgBox "OK"
Else if CDSub = 4 Then
MsgBox "Maybe"
Elseif CDSub = 5 Then
MsgBox "NO"
End If

Of course the if statement is more complex but the point I'm gong after
is that I need to combine the 2 and 3 conditions together.
Thanks
DS
 
Can this be done?

If CDSub = 2 or 3 Then
MsgBox "OK"
Else if CDSub = 4 Then
MsgBox "Maybe"
Elseif CDSub = 5 Then
MsgBox "NO"
End If

Of course the if statement is more complex but the point I'm gong
after is that I need to combine the 2 and 3 conditions together.
Thanks
DS
If CDSub = 2 or CDSub = 3 Then
 
The way you wrote it, you are asking Access to evaluate if CDSub=2, or If 3
.... ?!what does that mean?

If you are going to use the If/Then approach, you'll need to use something
like:

If CDSub =2 or CDSub = 3 Then...

Now, take a look at the Select Case expression in Access HELP. This will
give you a way to evaluate MANY options, and to combine your evaluating 2
and 3 in a single step.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Jeff said:
The way you wrote it, you are asking Access to evaluate if CDSub=2, or If 3
... ?!what does that mean?

If you are going to use the If/Then approach, you'll need to use something
like:

If CDSub =2 or CDSub = 3 Then...

Now, take a look at the Select Case expression in Access HELP. This will
give you a way to evaluate MANY options, and to combine your evaluating 2
and 3 in a single step.

Regards

Jeff Boyce
Microsoft Office/Access MVP
Thanks Jeff I see the error in my ways. I love Select Case but in this
case I need it for a rowsource in a listbox, so I'm kinda stuck with the
if statement.
DS
 
Thanks Jeff I see the error in my ways. I love Select Case but in this
case I need it for a rowsource in a listbox, so I'm kinda stuck with the
if statement.

Well, Select Case and If... Elseif... Else are *both* VBA constructs, and
neither will work in the rowsource for a listbox!

If nested IIF() calls are getting to complex or too inefficient, try a
Switch() function. It takes arguments in pairs, and steps through them left to
right, returning the second member of the first pair whose first element is
TRUE. E.g.

Switch(CDSub = 2 or CDSub = 3, "OK", CDSub = 4,"Maybe",
CDSub = 5,"NO", True, "Unexpected value")


John W. Vinson [MVP]
 
Back
Top