Results 1 to 4 of 4
  1. #1
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183

    IIF statement in Queries

    I have a query with Age field. I would like to group them based on the age entered.

    I have a code that looks like this:

    Code:
    AgeGroup: IIf([Age]<"65","Under 65",IIf([Age]>="65" And [Age]<"75","65-74",IIf([Age]>="75" And [Age]<"85","75-84",IIf([Age]>="85","85 and older","N/A"))))
    Everything works except when the age is 100 or above. The query will show 'under 65' for those people whose age is 100 or above.



    Please help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If your age is a numeric value, you don't want quotes around them. That gives you an alphabetic test rather than a numeric test, and alphabetically 100 is less than 65.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by pbaldy View Post
    If your age is a numeric value, you don't want quotes around them. That gives you an alphabetic test rather than a numeric test, and alphabetically 100 is less than 65.
    You are awesome!!!! Thank you so much for the quick reply!! really appreciate your help

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  2. Replies: 9
    Last Post: 08-27-2014, 11:34 AM
  3. iff Statement Between 2 queries.
    By smc678 in forum Queries
    Replies: 4
    Last Post: 07-22-2013, 01:37 PM
  4. Replies: 5
    Last Post: 03-03-2013, 07:18 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums