Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIF Function

Status
Not open for further replies.

KatGraham

Programmer
Feb 12, 2003
58
US
Can anyone tell me how to do a nested IF statement with AND or OR.

Is there a way to do:

IIF(txtOne=1 or 2 or 3 .... etc. or
IIF(txtOne=1 or txtOne=2 or txtOne=3 or

Do I have to do:
IIF(txtOne=1,IIF(txtOne=2, ... etc.

Help?
 
Kat,

Not sure if this is what you're looking for but maybe the SelectCase would work bette for you.

This example uses the Select Case statement to evaluate the value of a variable. The second Case clause contains the value of the variable being evaluated, and therefore only the statement associated with it is executed.

Dim Number
Number = 8 ' Initialize variable.
Select Case Number ' Evaluate Number.
Case 1 To 5 ' Number between 1 and 5.
Debug.Print "Between 1 and 5"
' The following is the only Case clause that evaluates to True.
Case 6, 7, 8 ' Number between 6 and 8.
Debug.Print "Between 6 and 8"
Case Is > 8 And Number < 11 ' Number is 9 or 10.
Debug.Print &quot;Greater than 8&quot;
Case Else ' Other values.
Debug.Print &quot;Not between 1 and 10&quot;

End Select
 
Can I do a case statement on a text field of a report? I'm trying to display certain data is the text field test is true. Example:

If txtStatus is 2, 5 or 6 then print A
If txtStatus is 1, 3, 4 or 7 then print B
 
You can in the On_Format Event of the report.

Select Case txtStatus

Case 2, 5, 6
NameOfLabel.Caption = &quot;A&quot;
Case 1,3,4, 7
NameOfLable.Caption = &quot;B&quot;



 
Ok, here's the deal:

I have a form that has:
txtProduct = LTD, STD, BOTH
txtStatus = combo box of All, Open, Closed etc.
txtIOP = combo box of Y or N

I have a report that has a TEXT box that I want to display txtProduct and &quot;Exclude ....&quot; if txtOIP equals Y. The difficult part is that this box should only display the &quot;Exclude...&quot; portion if txtStatus is Open.

I can't seem to get a case statement to work when I set it up in a module or in the report.
 
without quite knowing all the details, you can do a
iff(txtOne=1 or txtOne=2.....). Or and And statements work the same way. I have done it in the past and it works. The only problem I see if the statement gets too long sometimes Access doesn't like it.
 
Alternatively you could try using the CHOOSE function. That is if your options are sequential numbers starting at 1.

e.g answer = choose(columnvalue, valuefor1, valuefor2, valuefor3,....)
in your instance

NameOfLabel.Caption = choose(txtStatus,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;B&quot;,&quot;A&quot;,&quot;A&quot;,&quot;B&quot;)

Even better still if you use a combobox and put the status values in a table you can put some code in the combobox's AfterUpdate event to set the Caption. e.g.
NameOfLabel.Caption = cbStatus.column(2)

If the combobox has 3 columns (the index starts at 0) and the first is the Code for the Status i.e 1,2,3... and the second is the description and the third is the value you want tot set the caption to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top