I have a form based on a query. The form displays records in a tabulated fashion (like excel). I wish to place a toggle button on top of each column that would allow me to sort de records in an ascending or descending order for each individual column. Any help would be greatly appreciated. Thanks!
Here is a simple way do do what you want. Here we use the MouseDown event for whichever control that may be used to issue the sort order (you could also use the KeyDown event). The reason for this is because we have easy access to the shift button state. In other words, if a command button is used to initiate the sort order then under normal circumstances the sort order will be set as Ascending (default) when the mouse button is clicked onto the control. But, if the Shift key is held in the down position while the control is clicked then the sort order is set to Descending. This prevents the need to place a seperate control for the want of either a Ascending or Descending order.
Private Sub myControlsName_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Application.Echo False 'Turn Echo off to Prevent flicker
If Shift = 1 Then 'Is the Shift Key pressed (1 = yes : 0 = No)
Me.OrderBy = "[myTableFieldName] DESC" 'The table item to base the sort from.
Me.OrderBy = "[myTableFieldName]" 'The table item to base the sort from.
Me.OrderByOn = True 'Turn ON the Sort
Me.Requery 'Requery the Form
Application.Echo True 'Turn Echo back on