If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > If statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-09, 17:52
maldonadocj maldonadocj is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Red face If statement

Hi,

Can someone pls. assist me with a query I would like to write in Access. The objective of the query is to categorize yearly data into specific term buckets.



Examples noted below:
Term= 3.8 yrs >> Expected result= "< 5 yrs"
Term= 7.9 yrs >> Expected result= "10 yrs"

I wrote the following query but it does not work:
IIf(Is Null ([Term])=Is Null, " ", (IIf([Term]<=5), "< 5 yrs",(IIf([Term]>5 AND ([Term])<=7),"7 yrs", (IIf([Term]>7 AND ([Term])<=10),"10 yrs", (IIf([Term]>10 AND ([Term])<=15),"15 yrs","> 15 yrs"))

I appreciate your assistance in this matter.
Reply With Quote
  #2 (permalink)  
Old 10-12-09, 18:19
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
I would go with a lookup table instead.

Any reason you can't do that?
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #3 (permalink)  
Old 10-12-09, 18:22
maldonadocj maldonadocj is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Hi Teddy,

Can you pls. elaborate on the lookup table? Are you referring to creating a seperate table in Access that would contain the term buckets and join this table with the original table?

Thank you

Last edited by maldonadocj; 10-12-09 at 18:25.
Reply With Quote
  #4 (permalink)  
Old 10-28-09, 00:49
A Waterman A Waterman is offline
Registered User
 
Join Date: Sep 2009
Posts: 11
When I count the round brackets in your expression, I got 13 open and 10 closed. I suspect you should have the same number each way.

If you write it out on a bit of paper, and for each open round bracket, label it with a letter (so, first one is a, second one is b...), and then find what you believe is the closing round bracket for a and label it a, and the same for b and so on, you should see where it is out of step. The format of IIF is IIF(expr,truepart,falsepart) - balanced round brackets.

I hope this is some help to you.
Reply With Quote
  #5 (permalink)  
Old 10-29-09, 13:31
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
Quote:
Originally Posted by maldonadocj View Post
Hi Teddy,

Can you pls. elaborate on the lookup table? Are you referring to creating a seperate table in Access that would contain the term buckets and join this table with the original table?

Thank you
Precisely.

This approach would also grant you better flexibility for reporting as you can sort/group/sum/etc on those buckets while getting friendly names at the same time "for free".
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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