Results 1 to 6 of 6
  1. #1
    orangeman2003 is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    21

    custom sorting with IIF statement

    Hi...I need some help to finish an IIF statement. The weird thing is I can perfectly do what I want to in the design view of my query editor but when I try to do it in the report expression builder can't get it.



    I'm trying to do a custom sort where Tier 1 is sorted alphabetically and tier 2 is custom sort. The way it goes is where the name of tier 2 = the name of tier 1, sort this first, then do ascending.

    Example:

    Mavericks (tier 1)
    Mavericks (tier 1)
    Clippers (tier 2)
    Lakers (tier2)
    Wizards (Tier 2)

    my sql code is:

    ORDER BY tbl_baselinesystems.APPNAME, IIf(tbl_exchanges.OriginNode=tbl_baselinesystems.A PPNAME,0,1), tbl_exchanges.OriginNode;

    When I put either IIf(tbl_exchanges.OriginNode=tbl_baselinesystems.A PPNAME,0,1) or IIf(tbl_exchanges.OriginNode=tbl_baselinesystems.A PPNAME,0, IIf(tbl_exchanges.OriginNode=tbl_baselinesystems.A PPNAME,1)) into expression builder neither work. Is there a way for me to sort in an expression using regular sql.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Build all your sort fields in the query. Not in the report.
    And if the IIF statmts get too hairy, make a function. That way you only build it once, and not for every field.

  3. #3
    orangeman2003 is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    21
    I did the first part, I created the sort in the query and when you run it, it works great. for some reason when I add that query to the report and then I add the associated field it doesn't hold the sort. not too familiar with building a function...

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Sorting in reports works different. Seems report usually ignores the query sort. Use the report Grouping & Sorting functionality.
    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.

  5. #5
    orangeman2003 is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    21
    that's what I'm doing, I'm using an IIF statement to sort a custom expression.

    =IIf([OriginNode]=[APPNAME],0,1)

    this brings up a statement of order by clause conflicts with group by. it might just be that i can't sort it this way with an expression

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    I looked again at the data example in OP. Both Mavericks show tier 1, should one be tier 2?

    You could be right about the impracticality of this. You want to assign a priority ranking to the Mavericks tier 2 record because there is also a tier 1 Mavericks. This is a criteria that is dependent on value in another record. What if the Lakers also had a tier 1 - how would the output look?
    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.

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

Similar Threads

  1. Custom sorting records in report
    By tanyapeila in forum Reports
    Replies: 4
    Last Post: 03-26-2014, 12:32 PM
  2. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  3. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. IP Sorting
    By neo651 in forum Access
    Replies: 4
    Last Post: 05-24-2011, 01:08 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