We help IT Professionals succeed at work.

Ordering records on a continuous form

Derek Brown
Derek Brown asked
When using this expression:

Me.RecordSource = "Select * from Lock Order BY Lock Desc"

Is there any way to include a second column or field order at the same time. I.e.:

Me.RecordSource = "Select * from Lock Order BY Lock Desc" and then Me.RecordSource = "Select * from Lock Order BY Size Desc"
Watch Question

order by  [lock] desc, [size] desc
It has to be a single expression so:
Me.RecordSource = "Select * from Lock Order BY Lock Desc, Size Desc" 

Open in new window

You can add as many expressions as you'd like.
John TsioumprisSoftware & Systems Engineer
Distinguished Expert 2019

You can also keep the way of setting the RecordSource of your Form and then on Form Level (e.g. via a button) add additional sorting ..
I used it a lot in continuous forms with many fields to have a click event on the Labels of the fields to dynamically sort.
The Code is like this :
Me.OrderBy = "Size DESC"
Me.OrderByOn = True

Open in new window

Check the Ms Article on this : https://docs.microsoft.com/en-us/office/vba/access/concepts/forms-design/change-the-filter-or-sort-order-of-a-form-or-report
Jim Dettman (EE MVE)President / Owner
Fellow 2019
Most Valuable Expert 2017

and FYI, a good way to learn SQL is to open the query designer, build what you need, and switch to SQL view and see the resulting statement.

You can go the other way as well if you already have a SQL statement.   Switch to design view, paste in the SQL statement, switch to design view and modify as needed, then switch back.



I can't believe I have never noticed that in sql before. I don't normally have much need of two levels of order.

So simple, for once.

Thanks all!