Results 1 to 10 of 10
  1. #1
    bldrc is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    5

    Question IIF condition -Newbie

    Here's a current IIF string i'm trying to change/modify for Access 2007.



    X: Sum(IIf(IsNumeric(Left([Prod],1)),1,0)

    I'm trying to get it to add up only if [Prod] is 11 characters instead of the above in this format: "1234-A-56.7" (numbers, dashes, letters and decimal). I've tried using "Len" instead of "IsNumeric" but since it contains different characters, it gives me a syntax error. Any point in the right direction would be greatly appreciated.

    Kind Regards

  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,642
    By my count you're missing the ending parentheses of the Sum() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bldrc is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    5
    My apologies, I didn't copy the entire thing.

    It should be

    X: Sum(IIf(IsNumeric(Left([Prod],1)),1,0))

    Thanks

  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,642
    You get a syntax error when trying to create it or when trying to run it? Could the Prod field ever be Null?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    bldrc is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    5
    The syntax error happens when i try run it. the [Prod] field is never null and always in the same format.

    The above code works great for other items we have but I want to modify it to work for the 11 character "1234-A-56.7".

    I have no clue on where to begin.

    Thanks

  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,642
    Can you post the db, or a representative sample? I just did a brief test and a query with that formula did not error on that value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    bldrc is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    5
    Here's a sample list of product numbers. I don't need it to give me a sum for the 6 digit numbers.

    Thanks for your help.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    This returns 33 for that data:

    X: Sum(IIf(Len([Prod])=11,1,0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    bldrc is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    5

    Thumbs up

    That did the trick, pbaldy. Exactly what I was looking for. Thanks for all your help.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem, and welcome to the site.
    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. where condition within a macro
    By kstyles in forum Reports
    Replies: 3
    Last Post: 04-08-2011, 03:58 PM
  2. DMax Condition
    By Luis Ferreira in forum Forms
    Replies: 3
    Last Post: 11-05-2010, 09:48 AM
  3. Like condition for 1 column help pls!
    By stodd in forum Queries
    Replies: 1
    Last Post: 03-14-2010, 01:51 AM
  4. hours + condition
    By Miriam in forum Queries
    Replies: 0
    Last Post: 08-09-2009, 06:46 AM
  5. How to use IIF condition
    By nshaikh in forum Queries
    Replies: 4
    Last Post: 09-12-2008, 01:23 AM

Tags for this Thread

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