User choosing sort/group order at query runtime

  • Thread starter Thread starter Allen Browne
  • Start date Start date
A

Allen Browne

The simplest way to do this is just to set the OrderBy property of your form
to the name of a field. Remember to set OrderByOn as well.

This kind of thing:
Private Sub cmdSortBySurname
Me.OrderBy = "Surname"
Me.OrderByOn = True
End Sub

For a more efficient approach you could create the SQL string on the fly,
and assign it to the RecordSource of the form.

For reports, see:
Sorting Records in a Report at run-time
at:
http://members.iinet.net.au/~allenbrowne/ser-33.html
 
It sounds like you are trying to create a highly flexible search capability,
with sorting/grouping. Have you checked the mvps.org/access website? Have
you checked the Access XXXX Developer Handbook (Getz, et. al.)?

Generally, one approach is to create a SQL statement on the fly, in the
procedure, evaluating all the settings and selections on your form when the
single <Do It!> button is clicked.
 
I looked in the query newsgroups and saw several links to pages that
hadexamples of how to pass sorting and grouping to a query at runtime, but
all the pages were dead links. Is there an easy way to do this with Access
2000 (other than making a separate query with the sort/group set different
in every one, and having a bunch of command buttons on a menu opening a
different one)?

I tried putting a form's unbound control name in the sort/group cell of the
query grid, and it didn't work.

Thanks for any help
 
Back
Top