Results 1 to 6 of 6
  1. #1
    tamales is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2019
    Posts
    3

    Form sort problem. Sorts column in ascending order but not descending order.

    I have a series of labels where I created a click event to sort on that column when clicked. I included 3 of them. For some reason the Private Sub Schedule_Description_Label_Click() does not sort in descending order. it will sort in ascending order. All others, there are 7, all work fine. Click once that column sorts sort ascending, click again that column sorts descending. Only that code has the problem.



    The source of the form is a query results. The values in the Schedule_Description are "monthly", "weekly" and "quarterly".



    Private Sub Data_Profile_Name_Label_Click()

    If Me.OrderBy = "[Data Profile Name]" Then
    Me.OrderBy = "[Data Profile Name] DESC"
    Else
    Me.OrderBy = "[Data Profile Name]"
    End If
    Me.OrderByOn = True


    End Sub


    Private Sub Schedule_Description_Label_Click()

    If Me.OrderBy = "[Schedule Description]" Then
    Me.OrderBy = "[Schedule Description] DESC"
    Else
    Me.OrderBy = "[Schedule Description]"
    End If
    Me.OrderByOn = True


    End Sub

    Private Sub Last_Run_Date_Label_Click()


    If Me.OrderBy = "[Last Run Date]" Then
    Me.OrderBy = "[Last Run Date] DESC"
    Else
    Me.OrderBy = "[Last Run Date]"
    End If
    Me.OrderByOn = True


    End Sub
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Don't see anything wrong with code.

    If you want to provdide db for analysis, follow instructions at bottom of my post.

    In future, please post lengthy code between CODE tags to retain indentation and readability (although yours is not so bad since it is simple code).
    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.

  3. #3
    tamales is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2019
    Posts
    3
    Ok I attached the basic DB

    Sorry there was ODBC I forgot to remove. The current copy should be good.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    This is very weird. The table won't DESC sort on this field. I manually set the OrderBy property in form design to [Schedule Description] DESC and that works when the form first opens. The code runs but SortBy property will not programmatically accept that criteria.

    I added an underscore for the space in field name and now it works in table. Only thing I can think is that Description is a reserved word and Access is confused by its use in field name, in spite of the [] in code.

    Then fix query and form design and code. All works.

    Another example of why not to use spaces in naming convention.
    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
    tamales is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2019
    Posts
    3
    Thank you very much. I see it is just Access being Access. I will remember your suggestion and pass it along.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I see it is just Access being Access.
    No, that's you using a word that is reserved and expecting to get away with. It is also a commandment of experienced db developers that "Thou shalt not use spaces or special characters, save perhaps for underscore, in any database object names". If you violate these guidelines, most database types will balk, thus it has little to do with Access specifically. You can ensure that you never use a reserved word by adopting one of the common naming conventions.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2018, 08:22 PM
  2. Sort Order problem
    By Chris@harveynorman in forum Reports
    Replies: 8
    Last Post: 11-22-2016, 10:42 PM
  3. sorting table field in ascending order
    By picyx in forum Access
    Replies: 7
    Last Post: 11-18-2014, 02:24 PM
  4. How to order columns in ascending order?
    By darkingthereturn in forum Access
    Replies: 5
    Last Post: 06-18-2012, 05:24 AM
  5. Make TEXTBOXES sort by DESCENDING order
    By taimysho0 in forum Programming
    Replies: 1
    Last Post: 12-05-2011, 04:52 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