Link to home
Get AccessLog in
Avatar of Derek Brown
Derek BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Ordering records on a continuous form

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"
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

Link to home
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
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.
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 :
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.

Avatar of Derek Brown


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!