Results 1 to 7 of 7
  1. #1
    Dormie is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    39

    Looking for suggestions on Long IIF statment

    Hi, I was wondering if anyone could give me a suggestion or if there is a way to make my IIF statement cleaner.

    Basically, I have a bunch of numbers in a single field I'm looking to round based on their value. For example, I'm rounding below 1 to 1, below 5 to 5 and so on. I'm looking at probably not the longest iif statement ever made but long for me. Plus, it's very hard to read incase I want to modify....



    Is this something that could be handled by VBA (I don't really have any experience in)? Maybe there is a way to do it cleaner in Excel? I'm not really too sure what my best avenue is but hoping for a couple suggestions over the long statement in expression builder.

    Thanks in advance!

  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,521
    I'm not clear on what you're trying to achieve, but I'd probably opt for a VBA function over a long, nested formula. Maybe this gets you started:

    http://www.baldyweb.com/Function.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Consider:

    Switch([field]<=1,1, [field]<=5,5, [field]<=10,10)

    How high do the numbers go? For numbers greater than 1, do you want to round up to multiple of 5?

    Otherwise, as Paul suggests, anything more complicated will likely require a custom function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Suggest you step back and tell us in plain English about the "business" that this database will support.
    Just as you would tell someone who knows nothing of you, your environment nor database.
    No jargon.

    Good luck.

  5. #5
    Dormie is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    39
    Thanks June7 & pblady, the more I look into it. It seems the custom function should do the job. I wasn't really aware of it before and I'm sure exactly what I'm doing but I'm learning.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, post back if you get stuck creating one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    if your rounding points are in steps of 5, consider the partition function (although<1 would be to be treated separately). Perhaps something like

    val(iif(field<=1,"1",mid(partition(field,1,999,5), instr(partition(field,1,999,5),":")+1)))

    change 999 to any max number to meet your needs - the above will return a 0 if your field value exceeds it

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

Similar Threads

  1. iF THEN VBA STATMENT
    By GCLIFTON in forum Queries
    Replies: 16
    Last Post: 07-15-2016, 02:43 PM
  2. Query taking too long, suggestions?
    By theperson in forum Queries
    Replies: 11
    Last Post: 05-29-2013, 10:17 AM
  3. if statment
    By ismailkhannasar in forum Access
    Replies: 3
    Last Post: 01-31-2013, 06:48 AM
  4. if statment or case statment?
    By whojstall11 in forum Forms
    Replies: 4
    Last Post: 07-09-2012, 01:44 PM
  5. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM

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