View Single Post
  #4  
Old May 11th, 2010, 08:05 PM posted to microsoft.public.access.forms
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default How do I sort a listbox by field

You provided the code you use to "fill" the listbox, ORDERed BY
[PersonLastName], [PersonFirstName].

Copy that SQL statement, but change the field you use in the ORDER BY clause
to reflect the column on which you wish to sort.

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Bruce Rodtnick" wrote in message
...
That's what I had in mind...but I'm not addressing it right...I made some
buttons with this code:

Me!lstMailTo.RowSource.OrderBy = Email
Me!lstMailTo.OrderByOn = True
Order By Email

'QuickList.RowSource = TheConstantValue
'Me.QuickList.Requery

Didn't work...

Another :

Dim strSQL As String

'set row source for list box
strSQL = ("[FirstName] & " " & [LastName] AS Name, Personnel.Email,
Personnel.[Voice Part]) _
FROM Personnel
WHERE (((Personnel.Email) Is Not Null) And ((Personnel.Status) =
"Active"))
Me.lstMailTo.Recordset OrderBy = "Personnel.LastName",
"Personnel.FirstName";

Me!lstMailTo.RowSource = strSQL
Me!lstMailTo.Requery

but I'm getting all kinds of errors.

B


"Jeff Boyce" wrote in message
...
Bruce

One approach is to add command controls "above" the listbox and use the
Click event on each to set the Listbox's source to a different SQL
statement (i.e., ORDER BY x -- whatever the command button is the
'label/header' for).

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Bruce Rodtnick" wrote in message
...
I have a listbox that I've populaed using the row source

SELECT DISTINCTROW [FirstName] & " " & [LastName] AS Name,
Personnel.Email, Personnel.[Voice Part], Personnel.LastName,
Personnel.FirstName
FROM Personnel
WHERE (((Personnel.Email) Is Not Null) AND
((Personnel.Status)="Active"))
ORDER BY Personnel.LastName, Personnel.FirstName;

I have three columns and I would like to be able to sort by the columns.
In other words, sort by Name, then later sort by Email or [Voice Part].
I've seen a bunch of examples and tried them but nothing seems to work.

Bruce