By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,385 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,385 IT Pros & Developers. It's quick & easy.

Listbox - Sorting in order of selection

P: 1
I've created a listbox on a form to display a list of fields to be used to sort on a report. When users select from the listbox it sorts them in a number order. Is it possible to have it sort in order of which users select? Please help....

Here's my code:

Expand|Select|Wrap|Line Numbers
  1. Dim strsql As String
  2. Dim strYourSQLSelectFromStatement As String
  3. Dim strSQLWhere As String
  4. Dim varItem As Variant
  5. Dim strListLoanValues As String
  7.     strListLoanValues = Forms!frmreport!List7.Column(0, varItem)
  9.       If (Forms!frmreport!List7.ItemsSelected.Count = 0) Then Exit Function
  11.       strYourSQLSelectFromStatement = ""
  13.       strSQLWhere = vbNullString
  15.     For Each varItem In Forms!frmreport!List7.ItemsSelected
  17.     strListLoanValues = Forms!frmreport!List7.Column(0, varItem) & ", "
  18.     strSQLWhere = strSQLWhere & strListLoanValues
  20. Next varItem
  22. strSQLWhere = Left(strSQLWhere, Len(strSQLWhere) - 2)  'Get rid of last comma
Jun 1 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 31,770
When you open the report you can pass a list of the fields you want to sort by in the OpenArgs parameter.
In the report's Open event procedure, you can use this list to set up the two properties SortBy & SortByOn.
Good luck.
Jun 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.