| ACC1x: How to Sort on Different Fields DynamicallyID: Q109715 
 | 
This article demonstrates how to design a filter that you can use to dynamically select the field on which to sort records.
The example below uses the Choose() function in a filter to sort the
records displayed on a form. Toggle buttons in an option group are used
to sort on different fields. The Choose() function accepts the value of
the option group as its first argument, and selects the field from the
subsequent list based on that value.
The following example describes how to create a form and a filter that
demonstrate this technique:
       Form: Customer Filter Test
       --------------------------------
          Caption: Customer Filter Test
          RecordSource: Customers
       Text Box: Company Name
          ControlSource: Company Name
       Text Box: Contact Name
          ControlSource: Contact Name
       Text Box: Address
          ControlSource: Address 
       Option Group: Field Selector
          AfterUpdate: Apply Sort Macro 
       Toggle Button: CompName
          OptionValue: 1
          Caption: Company Name
       Toggle Button: ContName
          OptionValue: 2
          Caption: Contact Name
       Toggle Button: Addr
          OptionValue: 3
          Caption: Address 
       Field: Choose(Forms![Customer Filter Test]![Field Selector], _
          [Company Name], [Contact Name], [Address])
       Sort: Ascending
       ' The order of the fields in the Choose() function must match the
       ' order of the OptionValue of the toggle buttons 
       Apply Sort Macro Actions
       ------------------------------------
       Action:  ApplyFilter
          Filter Name: Customer Sort Filter 
Microsoft Access "Language Reference," version 1.0, "Choose Function,"
page 65
For more information on the Choose() function, search for "Choose" using
the Microsoft Access Help menu.
Additional query words: change column dynamic sorting
Keywords          : kbusage FmsOthr 
Version           : 1.0 1.1
Platform          : WINDOWS 
Issue type        : kbhowto Last Reviewed: April 2, 1999