Results 1 to 4 of 4
  1. #1
    Kluaoha is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2017
    Posts
    20

    ORDER BY Sorting Integer Field as Text


    I have a query selecting many fields, and based on a boolean value I want it to be sorted along one of two fields:

    ...
    ORDER BY IIF(GetBooleanValue(),[MyTable].[MyField1],[MyTable].[MyField2]);

    GetBooleanValue is a function in Globals module, MyField1 is a long integer field, MyField2 is a short text field.
    It works just fine, except when GetBooleanValue() is true, it sorts MyField1 as if it were text.

  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
    My first thought is to do the sorting in the form/report the query is used for.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    I tested this and doesn't matter if True or False, only sorts on Field1, never Field2 and alpha sort is applied to Field1.

    However, if both fields are number type then number sort is applied and then the True/False condition works and Field2 will return.

    So my conclusion is IIf returns a string if either field is text, so both fields must be number type if you want number sort.
    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
    Kluaoha is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2017
    Posts
    20
    Thanks, I got it to work by just changing the RowSource property when the Boolean changed.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-09-2015, 10:34 AM
  2. how much text in long integer field?
    By accessmatt in forum Database Design
    Replies: 10
    Last Post: 12-22-2014, 03:54 PM
  3. sorting table field in ascending order
    By picyx in forum Access
    Replies: 7
    Last Post: 11-18-2014, 02:24 PM
  4. Replies: 1
    Last Post: 03-27-2014, 06:39 AM
  5. Replies: 1
    Last Post: 10-09-2008, 04:48 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