Results 1 to 6 of 6
  1. #1
    Miles R is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Mar 2019
    Posts
    176

    Strange sort order of records on a form.


    Can't figure out what is happening here. I have a form with a recordset based on a query. If I set the OrderBy (with OrderBY on load true) in design mode, the order of the records on the form is correct. However, I wanted to set the OrderBy in VBA. When I do this (and clear the value in design mode), it totally ignores the sort order I have just set (in the Form Open Event code). In fact the sort order it is using seems to be some saved sort order based on an older version of data in my table.
    (i.e. I had two records in the wrong order, so I changed them, but the form was still sorting based on the records in the wrong order).
    Hope this makes sense.
    Put simply, does it work to set the OrderBy in VBA, or do you have to do something else as well?
    Last edited by Miles R; 03-27-2019 at 12:57 PM. Reason: Did not complete before it got posted

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    Now you've added more info, but you still haven't given us a clue what you are sorting by.
    So I'm going to take a guess.
    Are you sorting by a field with numbers that is actually a text field?
    If so, it will sort in 'alphabetical order' e.g. 1,10,11,12,13,2,23,25,3,4

    If that's not it...please can you at least tell us what the recordset is & show a screenshot of the sorted records
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,960
    Post your code or db for analysis.

    Did you set OrderBy as well as OrderByOn properties?

    Does work for me.
    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
    Miles R is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Mar 2019
    Posts
    176
    Colin, no I was sorting by several fields, text and numbers.
    However I think June7 has solved the problem. I did not set OrderBYOn. I did not see this property in the Design Mode, so missed it in the VBA.
    Just tried this and it now works.
    Will have to research Orderby properties a bit more. Am a bit rusty on Access, despite having used it for 15 years.
    Thanks.

  5. #5
    Miles R is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Mar 2019
    Posts
    176
    Great thanks June, I had not set OrderByOn. It works now.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    Glad you have a solution.
    If you use the OrderBy approach, you do need to exactly the same whether using vba or the property sheet
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 13
    Last Post: 11-12-2017, 01:27 AM
  2. Replies: 16
    Last Post: 11-09-2015, 10:44 AM
  3. Sort Order for Records in Subforms
    By The Professor in forum Forms
    Replies: 4
    Last Post: 06-29-2013, 06:39 AM
  4. Sort order in a sub form
    By roar58 in forum Forms
    Replies: 1
    Last Post: 03-17-2012, 08:57 PM
  5. Access 2003, sort order property of a form
    By Rick West in forum Forms
    Replies: 11
    Last Post: 09-17-2009, 08:28 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