Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button Sorts 1

Status
Not open for further replies.

OzSupra

IS-IT--Management
Nov 22, 2003
18
AU
I have a continuous form that has buttons at the top of each column. I would like to sort each column by the corresponding heading button [in ascending order]. I would prefer not to have write a specific query as I would like to apply the same process to multiple forms.

Ta, in advance, Adrian.
 
FOUND THE ANSWE - Works a treat!

Set the OrderBy property of your form, depending which label/button was
clicked.

Paste the function below into a module, and save. You can then call it from
any form. For example, set the On Click property of the label over the
Surname column to this:
=SortForm([Form], "Surname")
(Note: The "[Form]" bit stays exactly like that.)


Public Function SortForm(frm As Form, ByVal sOrderBy As String)
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: Command button above a column in a continuous form:
' Call SortForm(Me, "MyField")

If Len(sOrderBy) > 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top