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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Button

Status
Not open for further replies.

kwill

Technical User
Aug 15, 2001
49
US
I'm trying to make a sort button on my form. Anyone know what the VBA is? thanks, mucho
 
I use the following function in a form module:

Public Sub ChangeSortOrder(frm As Form, strFld As String)
On Error GoTo ErrHand

If frm.OrderBy = strFld Then
frm.OrderBy = strFld & " DESC"
Else
frm.OrderBy = strFld
End If
frm.OrderByOn = True

ExitProc:
Exit Sub

ErrHand:
MsgBox Err.Number & " " & Err.Description
GoTo ExitProc

End Sub

Then simply call the function from an on-click procedure of your button like the following:

Call ChangeSortOrder(Me, "MyButton")

There are other ways but I like to use a function if I have a number of buttons, such as column sorting on a continuous form layout.

Paul
 
kwill

Sorry, I hit the submit button too fast.

The strFld has to be the underlying field that the button is to sort.

Call ChangeSortOrder(Me, "MyFieldName")

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top