Results 1 to 6 of 6
  1. #1
    TheWolfster is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Feb 2010
    Posts
    25

    Question Syntax error (comma) in query expression?

    Hello again!



    I'm trying to write a IIF function, but I keep getting this error. Have I set it up wrong?

    Code:
    Negative behavior: IIf([T1_HAngerTotNoInt]="1", "1", IIf([T1_HDisgtTotNoInt]="1", "1", IIf([T1_HCntmpTotNoInt]="1", "1", IIf([T1_HWhineTotNoInt]="1", "1", IIf([T1_HSadnsTotNoInt]="1", "1", IIf([T1_HFerTotNoInt]="1", "1", IIf([T1_HDominTotNoInt]="1", "1", IIf([T1_HBeligTotNoInt]="1", "1", IIf([T1_HDefenTotNoInt]="1", "1", "0")))))))))
    The raw data is only 1's and 0's.

    The full error:



    (its physiology data if you're curious)

    Thanks if anyone can help! I'm still a novice

    Edit: Ohhh, they're supposed to be separate fields...do I have to split up the IIF statement into 9 parts?

    Edit2: Even individual IIF's don't work. Hmm...

  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,525
    I'm not sure how many IIf() functions you can nest, but you might want to check out the Switch() function. I think it will be a lot simpler.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TheWolfster is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Feb 2010
    Posts
    25
    Yeah, I'm thinking there might a limit, but setting up just 1 IIF statement gives me the same error.

    How would Switch() work? Wouldn't that take a number and give it a value (1=A, 2=B) -- just setting TRUE but noth both? I think IIF is perfect for me. (Unless I'm wrong? I don't know too much about Access).

    But thanks for the reply, somehow I feel less anxious :P
    Last edited by TheWolfster; 05-10-2010 at 12:19 PM.

  4. #4
    TheWolfster is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Feb 2010
    Posts
    25
    Code:
    Negative behavior: IIf([T1_HAngerTotNoInt]="1",1,IIf([T1_HDisgtTotNoInt]="1",1,IIf([T1_HCntmpTotNoInt]="1",1,IIf([T1_HWhineTotNoInt]="1",1,IIf([T1_HSadnsTotNoInt]="1",1,IIf([T1_HFerTnTotNoInt]="1",1,IIf([T1_HDominTotNoInt]="1",1,IIf([T1_HBeligTotNoInt]="1",1,IIf([T1_HDefenTotNoInt]="1",1,0)))))))))
    Hmm, I rewrote it as follows, and now it works?



    Edit: Sorry, double post!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    I'm glad you got it working, but Switch() would have been simpler. The example from Help:

    Switch(CityName = "London", "English", CityName = "Rome", "Italian", CityName = "Paris", "French")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    TheWolfster is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Feb 2010
    Posts
    25
    I'll try that, thanks!

    Guess its okay to mark this as solved?

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

Similar Threads

  1. Replies: 13
    Last Post: 12-05-2011, 05:10 AM
  2. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM
  3. Syntax error (comma) in query expression
    By KLynch0803 in forum Programming
    Replies: 3
    Last Post: 01-18-2010, 03:35 AM
  4. Replies: 1
    Last Post: 10-07-2009, 07:36 AM
  5. sql syntax error
    By SMAlvarez in forum Access
    Replies: 1
    Last Post: 03-12-2009, 09:43 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