Dynamically sorting subform records based on option box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that contains an option box and a subform. I would like to sort
the subform based on the option box selection. For example if option 1 is
selected, after update, sort the subform by city, if option 2 sort by zip,
option 3 by last name, etc.

Any suggestions/techniques?

Thanks
Jim T.
 
On Mon, 24 Jan 2005 19:25:02 -0800, "Jim Tinder" <Jim
I have a form that contains an option box and a subform. I would like to sort
the subform based on the option box selection. For example if option 1 is
selected, after update, sort the subform by city, if option 2 sort by zip,
option 3 by last name, etc.

Any suggestions/techniques?

I'd suggest using the option group's AfterUpdate event to actually
change the Recordsource property of the subform's Form object:

Private Sub optSortBy_AfterUpdate()
Const strSQL As String = "SELECT blah, blah, blah FROM PeopleAddress"
Select Case optSort
Case 1 ' city
strSQL = strSQL & " ORDER BY City;"
Case 2 ' zip
strSQL = strSQL & " ORDER BY Zip;"
Case 3 ' lastname
strSQL = strSQL & " ORDER BY Lastname;"
...
End Select
Me!subMySubform.Form.Recordsource = strSQL
End Sub

John W. Vinson[MVP]
 
Back
Top