Results 1 to 12 of 12
  1. #1
    gr8dane is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2024
    Posts
    6

    Strange Query Design Grid Behavior


    I've created a number of databases for my personal use over the past three decades, mostly in mdb format, some converted to accdb as needed. The one I'm currently creating is the first one that's accdb from the start and I'm seeing some behavior I've never seen before.

    When designing a query and setting a sort order on a field, a duplicate column gets created at the right end of the grid so that I have one column with the sort showing and one without. Something like this:
    Code:
    --------------------------------------------------
    | DateDue  | PriorityID | DateDue   | PriorityID |
    | tblTasks | tblTasks   | tblTasks  | tblTasks   |
    |          |            | Ascending | Ascending  |
    --------------------------------------------------
    The query still works, but it gets really confusing when I'm designing multi-column sorts.

    Is this some new behavior in v.2010 (my newest version... yeah, I know, I'm way behind)? Is there a setting somewhere that I can change to make it stop doing this?
    Last edited by gr8dane; 04-17-2024 at 04:34 AM. Reason: Code won't line up

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,431
    Depends on the query - show the whole sql

  3. #3
    gr8dane is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2024
    Posts
    6
    SELECT tblTestTasks.Task, tblPriorities.Priority, tblPriorities.PriorityRGB, tblTestTasks.DateDue, tblTestTasks.PriorityID, tblTestTasks.ProjectID, tblTestProjects.PriorityID, tblTestProjects.Project, IIf(IsNull([tblTestTasks].[DateDue]),1,0) AS [Order]
    FROM (tblTestTasks LEFT JOIN tblPriorities ON tblTestTasks.PriorityID = tblPriorities.PriorityID) LEFT JOIN tblTestProjects ON tblTestTasks.ProjectID = tblTestProjects.ProjectID
    WHERE (((tblTestTasks.DateDue)>#4/12/2024# Or (tblTestTasks.DateDue) Is Null))
    ORDER BY IIf(IsNull([tblTestTasks].[DateDue]),1,0), tblTestTasks.DateDue, tblTestTasks.PriorityID;

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You already created a calculated field for Order; why not use it?
    ORDER BY [Order], tblTestTasks.DateDue, tblTestTasks.PriorityID;

    That is probably where your extra query field comes from.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    gr8dane is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2024
    Posts
    6
    First, because the SQL is Access-generated. Secondly, because I read that Access doesn't allow that. I tried it out, though, and it resulted in another duplicate column named Order and when I tried switching to DS view, I got a parameter pop-up for Order.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I took it that [Order] as a calculated field you have created would not conflict with the word "order" in the ORDER BY clause. However, I just reviewed my source for reserved words and see that it is reserved - for Jet, SQL Server and ODBC so maybe I would use something else and see if the prompt goes away. However, upon reviewing I'm not understanding why you have the expression a second time. It looks to me like your result would be
    ORDER BY 1 (or zero), tblTestTasks.DateDue, tblTestTasks.PriorityID;
    1 or 0 is going to be interpreted as a query field, no?

    I'm afraid that your code snippet above isn't really revealing the issue to me. A sort on 2 or more fields should sort by field1, then field2, then field3 and so on, and as long as those fields are in the SELECT statement, they should be visible. There should be no repetition of query fields unless a field is in the SELECT statement more than once.

    Maybe a pic of your query design grid would help, if you can show all of it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Not sure why happens, just delete the duplicate and just have the 1 field with the sort on it. If this is a report, can set the sort in the report.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,948
    Quote Originally Posted by Bulzie View Post
    Not sure why happens, just delete the duplicate and just have the 1 field with the sort on it. If this is a report, can set the sort in the report.
    In fact Access reports take no notice of any external order in the first place, so if a report it HAS​ to be done in the report.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    gr8dane is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2024
    Posts
    6
    Quote Originally Posted by Micron View Post
    I took it that [Order] as a calculated field you have created would not conflict with the word "order" in the ORDER BY clause. However, I just reviewed my source for reserved words and see that it is reserved - for Jet, SQL Server and ODBC so maybe I would use something else and see if the prompt goes away.
    There doesn't seem to be a problem with using the word as an alias. Only with using it later in the SQL.

    However, upon reviewing I'm not understanding why you have the expression a second time.
    I don't understand it either. It's Access-generated.

    It looks to me like your result would be
    ORDER BY 1 (or zero), tblTestTasks.DateDue, tblTestTasks.PriorityID;
    1 or 0 is going to be interpreted as a query field, no?
    This query is the source for a continuous form. The purpose of IIf(IsNull([tblTestTasks].[DateDue]),1,0) is to make records without a due date show up after records with one. They then get sorted by priority.

    Maybe a pic of your query design grid would help, if you can show all of it.
    I'm attaching pics of the design grid and the resulting datasheet. I took Bulzie's advice and removed the non-sorting columns. That worked (once I remembered to make the remaining ones visible), but I'd still like to know why they got added in the first place.

    Click image for larger version. 

Name:	Query Design Grid.jpg 
Views:	21 
Size:	211.6 KB 
ID:	51696Click image for larger version. 

Name:	Query Datasheet.jpg 
Views:	21 
Size:	53.0 KB 
ID:	51695

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,431
    You could just order by

    [date due] is not null

  11. #11
    gr8dane is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2024
    Posts
    6
    What would that do? I want the records with a due date to rise to the top, sorted by due date. The rest should be ordered by priority. That's what my method does, but I don't understand what result I would get using your method.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,431
    Just suggesting a simpler and more efficient method

    Booleans are either -1 for true or 0 for false

    So sorting ascending, trues will appear before false.

    how you sort after that is down to you
    Last edited by CJ_London; 04-20-2024 at 10:14 AM.

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

Similar Threads

  1. Strange Behavior
    By GraeagleBill in forum Access
    Replies: 4
    Last Post: 08-13-2021, 04:01 PM
  2. Strange Behavior
    By Dave14867 in forum Forms
    Replies: 3
    Last Post: 06-16-2020, 03:52 PM
  3. Combo box strange behavior
    By Goyooper in forum Database Design
    Replies: 5
    Last Post: 06-02-2020, 12:40 PM
  4. Strange TransferSpreadsheet Behavior
    By JoeM in forum Programming
    Replies: 6
    Last Post: 08-05-2015, 07:47 AM
  5. Strange Behavior when Sorting
    By geniass in forum Queries
    Replies: 5
    Last Post: 09-02-2010, 03:53 PM

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