I found a brilliant and simple method to sort list box's to use.
A section of this code includes the following:
This is called as follows:
However, this only works if the form has one list box because the code in strSQl = ...... refers to the list box
I would like to enhance the code so that it can work on forms with multiple list box's. So I would like to add the name of the list box to the private sub routine, like this:
There is something wrong with: strList As ListBox! and I can't figure it out!
Where is my error and how do I fix it?
It would also make sense to change the Private Sub SortColumn(strField As String, strOrder As String) to public. Then I would not have to include it in every form.
Thanks in advance
A section of this code includes the following:
Code:
Private Sub SortColumn(strField As String, strOrder As String)
Dim strSQL As String
Dim strSorted As String
strSQL = Replace(Left(Me.lstCustomer.RowSource, Me.ListLength - 1), ";", " ")
strSorted = strSQL & " ORDER BY " & strField & strOrder & ";"
Me.lstCustomer.RowSource = strSorted
Me.lstCustomer.Requery
End Sub
Code:
Private Sub cmdSortArea_Click()
If Me.cmdSortArea.Caption = "" Or Me.cmdSortArea.Caption = "q" Then
Me.cmdSortArea.Caption = "p"
SortColumn Me.lstCustomer, "Area", ""
Else
Me.cmdSortArea.Caption = "q"
SortColumn Me.lstCustomer, "Area", " DESC"
End If
End Sub
I would like to enhance the code so that it can work on forms with multiple list box's. So I would like to add the name of the list box to the private sub routine, like this:
Code:
Private Sub SortColumn(strList As ListBox, strField As String, strOrder As String)
Dim strSQL As String
Dim strSorted As String
strSQL = Replace(Left(strList.RowSource, Me.ListLength - 1), ";", " ")
strSorted = strSQL & " ORDER BY " & strField & strOrder & ";"
Me.lstCustomer.RowSource = strSorted
Me.lstCustomer.Requery
End Sub
Where is my error and how do I fix it?
It would also make sense to change the Private Sub SortColumn(strField As String, strOrder As String) to public. Then I would not have to include it in every form.
Thanks in advance