Access 2007
How do I code an A-Z sort on a form?
Say the field is "LastName".
I want to put this code on a button(s) so the used can sort one column or
another.
thanks
dave
One column or the other. The Field (columns) names are fixed or do you
wish the user to select any field and sort by that (and why can't they
use the already in place A-Z or Z-A toolbuttons)?
If the Field name is fixed (LastName]....
Add a command button to the form.
Code it's Click event:
Me.OrderBy = "LastName"
Me.OrderByOn = True
If the user can select any field...
Me.OrderBy = Me.PreviousControl.Name
Me.OrderByOn = True
The user will place the cursor in the field to be sorted on.
Then clicks the command button.
Since Ascending is the default sort order, you do not need to
explicitly write it.
If you wish to sort Z-A then add to each of the above:
& " Desc"