Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "iif statement" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old June 5th, 2008, 11:57 AM
Barn Newbie
 
Join Date: Jun 2008
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
Barkol is an unknown quantity at this point
Default iif statement

I already know how to basically use the iif statement in a query, checking for true of false. For instance: iif(x=1,"X equals 1","X does not equal 1")

How would I go about doing multiple options using the iif statement in a query. I don't know much about VBA, so I'd like to keep this in a query.

For example, if x equals the following, I would like this displayed:

x=1 ----- "Enter Customer Information"
x=2 ----- "Edit Customer Information"
x=3 ----- "Delete Customer Information"
x=4 ----- "Exit"

You're help would be greatly appreciated. Thanks!!
Reply With Quote
Sponsored Links
  #2  
Old June 5th, 2008, 12:22 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

What you want is the switch function:
Code:
switch(x=1, "Enter Customer Information", 
x=2, "Edit Customer Information", 
x=3, "You get it")
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
The Following 2 Users Say Thank You to Wolffy For This Useful Post:
Barkol (June 5th, 2008), richyrich (June 5th, 2008)
  #3  
Old June 5th, 2008, 12:56 PM
Barn Newbie
 
Join Date: Jun 2008
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
Barkol is an unknown quantity at this point
Default

Thank you for your quick reply

That's what I needed
Reply With Quote
  #4  
Old June 5th, 2008, 12:59 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

No problem, its nice to get in first once in awhile
Reply With Quote
  #5  
Old June 5th, 2008, 11:12 PM
don94403's Avatar
Moderator


 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 63
Thanks: 3
Thanked 8 Times in 8 Posts
Blog Entries: 2
Rep Power: 1
don94403 is on a distinguished road

Awards Showcase
PHP Microsoft Access 
Total Awards: 2

Default

Quote:
Originally Posted by Barkol View Post
I already know how to basically use the iif statement in a query, checking for true of false. For instance: iif(x=1,"X equals 1","X does not equal 1")

How would I go about doing multiple options using the iif statement in a query. I don't know much about VBA, so I'd like to keep this in a query.

For example, if x equals the following, I would like this displayed:

x=1 ----- "Enter Customer Information"
x=2 ----- "Edit Customer Information"
x=3 ----- "Delete Customer Information"
x=4 ----- "Exit"

You're help would be greatly appreciated. Thanks!!
Basically, you just substitute another Iif() for each "false", so that it says, in effect: If this is true, then this is the value, if not, then If THIS is true, then THIS is the value, if not, then If THIS is true ... etc.

You have to be really careful with all the parentheses, and if you need more than a few conditions, it can get very hard to read or modify, not to mention running slow. Here's how your example should look:
Code:
Iif(x=1,"Enter Customer Information",
   Iif(x=2,"Edit Customer Information",
   Iif(x=3,"Delete Customer Information,
   Iif(x=4,"Exit","ERROR!"))))
As a quick check, the number of closing parentheses at the end needs to be the same as the number of conditions, excluding the last or default.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Tags
access, iif

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement stored procedure peebman2000 SQL Development 32 May 23rd, 2008 03:54 PM


All times are GMT -4. The time now is 11:50 AM.



Content Relevant URLs by vBSEO 3.2.0