Results 1 to 5 of 5
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    Error msg in Query

    I have a query to track NBA game progress by quarter using option buttons, one for each qtr as well as 1 for the half an another for a completed game. 1= 1st qtr, 2= 2nd qtr 3= halftime, 4 = 3rd qtr, 5 = 4th qtr and 0 = game complete. I can get the formula to work in a form but if I apply it to a query I get an error if 3 or 0 are selected.

    The formula that works is:

    Code:
    =IIf([Qtr]=1,1,IIf([Qtr]=2,2,IIf([Qtr]=4,3,IIf([Qtr]=5,4,IIf([Qtr]=3,"H",IIf([Qtr]=0,"C"))))))
    As applied in the query:


    Code:
    GmQtr:IIf([Qtr]=1,1,IIf([Qtr]=2,2,IIf([Qtr]=4,3,IIf([Qtr]=5,4,IIf([Qtr]=3,"H",If([Qtr]=0,"C"))))))
    And the complete SQL is:



    Code:
    SELECT NBAScoringTbl.ScoringID, NBAScoringTbl.Season, NBATbl.Conference, NBATbl.Division, NBAScoringTbl.Game, NBATbl.Nickname, NBAScoringTbl.Win, NBAScoringTbl.Loss, 
    NBAScoringTbl.Team, [Win] & "-" & [Loss] AS Record, [Win]+[Loss] AS GmPlayed, NBATbl.City, NBAScoringTbl.Scheduled, NBAScoringTbl.GmTime, NBATbl.Qtr, 
    IIf([Qtr]=1,1,IIf([Qtr]=2,2,IIf([Qtr]=4,3,IIf([Qtr]=5,4,IIf([Qtr]=3,"H",IIf([Qtr]=0,"C")))))) AS GmQtr
    FROM NBATbl INNER JOIN NBAScoringTbl ON NBATbl.NBAID = NBAScoringTbl.Team
    ORDER BY NBAScoringTbl.Game, NBATbl.Nickname, NBAScoringTbl.Win DESC , NBAScoringTbl.Loss;
    Any ideas where I went wrong?

    Jim O

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You don't need IIFs in a query.
    use a translation table and join it to the query.

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thank you for you response.

    As a learner I don't really understand quite what you are saying, I am not familiar with a translation table. Is it a sort of junction table? Do I create a table with one field being the number 0-5 and another field with the desired output?

    ID Number Output
    1 1 1
    2

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Looks like it might be a syntax error
    Code:
    GmQtr:IIf([Qtr]=1,1,IIf([Qtr]=2,2,IIf([Qtr]=4,3,IIf([Qtr]=5,4,IIf([Qtr]=3,"H", If([Qtr]=0,"C"))))))
    Should be "IIF"


    Alternatives to the IIF() function:
    (probably the best choice) is the SWITCH() function
    Code:
    GmQtr:Switch([Qtr]= 1, 1, [Qtr]= 2, 2,  [Qtr]= 3, "H", [Qtr]= 4, 3, [Qtr]= 5, 4,[Qtr]= 0, "C")

    Or
    the CHOOSE() function
    Code:
    GmQtr:GmQtr: Choose([Qtr],1,2,"H",3,4,"C")
    If you want to try the CHOOSE() function, you would have to make a change:
    1= 1st qtr
    2= 2nd qtr
    3= halftime
    4 = 3rd qtr
    5 = 4th qtr
    6 = game complete.

  5. #5
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thank you very much for you input.

    I will play around with it for a while, in the meantime I will mark this as solved.

    Thanks
    Jim O

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

Similar Threads

  1. Replies: 14
    Last Post: 03-31-2015, 05:20 PM
  2. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  3. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  4. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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