I tried this same code and keep getting blank boxes after update. It does
not appear to be writing any code to the SQL for the list box. Could you
please give me some insight? Thanks!
Here is my code:
'***For the list box:
SELECT [Select City Query].NAME, [Select City Query].IND_IDTE, [Select City
Query].PNAME1
FROM [Select City Query]
GROUP BY [Select City Query].NAME, [Select City Query].IND_IDTE, [Select
City Query].PNAME1;
'*** I tried adding the default ORDER BY and it did seem to help. No
changes were made to this code either way...
Here is the code for the option group:
Private Sub Frame40_AfterUpdate()
'*Frame40 is the name of my option group
Dim strSQL As String
Dim strNewOrder As String
strSQL = CurrentDb.QueryDefs("Select City Query").SQL
'***"Select City Query" is the name of my query the list is based on
Select Case Me.Frame40
Case 1
strNewOrder = "NAME"
Case 2
strNewOrder = "PNAME1"
Case 3
strNewOrder = "IND_IDTE"
'***These are my fields in the query that I want sorted
End Select
strSQL = Replace(strSQL, ";", " ORDER BY " & strNewOrder & ";")
Me.FirstCategory.RowSource = strSQL
'***FirstCategory is the name of my list box
End Sub
'*** I made the option group using the wizard. Do I need to do anything
else
'*** to the settings or the buttons within the option group? They all
show the
'*** correct default values. Any help would be greatly appreciated!
Klatuu said:
Here is how you do it.
Create a query that has all the fields you want in your list box, but do not
define a sort order.
Create the list box using the wizard. When it asks you what to base it on,
use the query you built. Then after you have saved it, you will have the SQL
as the rowsource for the list box. Edit the SQL (not the saved query) to
include the defalut sort order you want by adding the ORDER BY clause at the
end of the SQL.
Now, for sorting, use an Option Group. Create a button for each sort order
you want. Be sure the default option is the default oder by for the list
box. That is, If your defalut sort for the list box is div, then make option
button 1 div with a value of 1.
Now, in the After Update event of the Option Group:
(note that the values you put in strNewOder for each option should be the
field name you want to sort on)
Private Sub opgOrder_AfterUpdate()
Dim strSQL As String
Dim strNewOrder As String
strSQL = CurrentDb.QueryDefs("_ordertest").SQL
Select Case Me.opgOrder
Case 1
strNewOrder = "div"
Case 2
strNewOrder = "horsename"
Case 3
strNewOrder = "firstname"
Case 4
strNewOrder = "lastname"
End Select
strSQL = Replace(strSQL, ";", " ORDER BY " & strNewOrder & ";")
Me.lstActivity.RowSource = strSQL
End Sub
:
I have a list box with four columns (div, horse name, first name, last name)
with rowsource set to a query qryEntriesList. I can sort the list box any
way I want by sorting the query, but I want to provide the user with the
ability to sort the list box using either a drop down list, or a set of
command buttons. My command button always fails by blanking out the list
box.
This must be a well used application. Can you give me some guidance or send
me to an explanation.