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!

Soring on a subform

Status
Not open for further replies.

richmond88

IS-IT--Management
Sep 25, 2003
32
GB
I have a subform that I want to sort both in ascending and descending order. It can be sorted on any one of 4 fields.

The subform has a query bound to it.

I presumably have 4 toggle buttons.

This may be a bit vague but can someone help me with the code to do it.

Thaks
 
Richmond,

Here is one approach that works well for form's in continuous view.

Set the subform's OrderByOn property to True.

Add command button's in the form header to serve as column headers/labels.

And then paste the following into the button's OnClick event. YourFieldName will be whatever field you wish to sort by,

Dim strOrderBy As String
Static x As Boolean
x = Not x
If x Then
strOrderBy = "YourFieldName" & " ASC"
Else
strOrderBy = "YourFieldName" & " DESC"
End If
Me.OrderBy = strOrderBy


Cheers,
Bill
 
Thanks for the replies folks.

I have decided to go with obli's solution.

I do have a problem with it though. I am sorting on 2 fields - StudentName and Effor. The student name works fine but I get a runtime 2001 on Effort Button - You cancelled previous operation.

Below is the code that I am using.

Private Sub cmdOrderEffortATS_Click()
'Set First Name order in ascending order and apply captions
Dim response As Integer
response = basOrderby("EffortATSPercentageTotal", "asc")
Me!cmdOrderEffortATSDesc.Visible = True
Me!cmdOrderEffortATSDesc.Caption = "v Application v"
Me!cmdOrderEffortATSDesc.SetFocus
Me!cmdOrderEffortATS.Visible = False
'Me!lstSearch.SetFocus

End Sub


Private Function basOrderby(col As String, xorder As String) As Integer
Dim strSQL As String

'Clear captions from command buttons
ClearCaptions

'Set row source for list box
strSQL = "SELECT * "
strSQL = strSQL & "FROM qselXCurricularHOYTutorYrList "
strSQL = strSQL & "ORDER BY " & col & " " & xorder
Me.RecordSource = strSQL ****BOMS OUT HERE****
Me.Requery

End Function

Any Help will be gratefully appreciated

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top