Sort Records in listbox (1 Viewer)

JPR

Registered User.
Local time
Today, 13:35
Joined
Jan 23, 2009
Messages
231
Hello,

back for some advice and would appreciate your help.

I have a form with a list box (List0), a text box (txtLName) used as query criteria and a cmd button which runs the query as record source of the list box.

On the Click Event of a cmd button I have this code:

Code:
If Len(List0) & "" > 0 And DCount("*", "qryLNAME") > 0 Then
Me.List0.RowSource = "qryLNAME"
Me.List0.Requery
Else
MsgBox "Sorry, no records were found.", vbInformation, "Search Menu"
Me.txtLname.value = Null
Me.txtLname.SetFocus
Exit Sub
End If

Exit Sub

End If

I was now hoping to add another cmd button to sort records in the listbox (ascending and descending at the same time). I have found a lot of examples, but just cannot get it working. Do you think this is a good practice? I do want to different button. Thank you for your help.
 
What is not working?
It could be as easy as
Code:
Select * from qryLname ORDER BY LName ASC/DESC
In fact you could default to ASC and use one button to toggle the sort order?

No need to requery either, when you set a new rowsource.[/code]
 
Last edited:
you could also run the query and use the following to test if records returned.

Code:
if not Me.List0.ListCount > 0  then 
     MsgBox "Sorry, no records were found.", vbInformation, "Search Menu"
     Me.txtLname.value = Null
     Me.txtLname.SetFocus
end if
 

Users who are viewing this thread

Back
Top Bottom