Sorting in a Graph said:
I want to add a command button to a form to resort the records in the form. I
do many command buttons, but don't know how to associate the button to the
query assigned to the form. How do I link the button to the form to reorder
or requery the records up?
Are you using the form's OrderBy property to sort, or the query that the
form is based on?
Also, is there an issue with using the toolbar/right click methods to sort?
Are you looking to alter which field you are sorting by (e.g. a combo box
for the fields and a button to perform the action on the selected field)?
There are several different methods by which to code the button; depending
on how you have your record source set up for the form and what exactly you
are trying to do here. Is the RecordSource a SQL statement, a query, or
<eek> the table itself?
Are you looking to dynamically sort by a variety of field names, or to sort
by one field only? A little more detail might make it easier to answer your
question, but here's some sample code if you are currently using the form's
Order By property to sort and simply want to reorder (this will also work to
quickly reverse the order if the toolbar/right click sort methods have been
used to select the sort field):
If InStr(1, Me.OrderBy, "DESC") = 0 Then 'Is the current sort descending?
Me.OrderBy = Me.OrderBy & " DESC" 'if not, add the ' DESC'
Else
Me.OrderBy = Replace(Me.OrderBy, " DESC", "") 'if so, remove the 'DESC'
End If