Code Examples

Sort A Field In Descending Order

acCmdSortDescending

The following code sorts a field in descending order. Create a button called cmdSortDesc and put the code behind it.

'***************** Code Start *******************
' Code by Terry Wickenden

Sub cmdSortDesc_Click()
  On Error Goto ErrHandler
  Screen.PreviousControl.SetFocus
  DoCmd.RunCommand acCmdSortDescending
  Exit Sub

ErrHandler:
  Select Case Err
    Case 2046
      'Command not available
      MsgBox "Sorting is not available at this time.", vbCritical, "Not Available"
    Case Else
      MsgBox Err.Number & ":-" & vbCrLf & Err.Description
  End Select
End Sub

'****************** Code End ********************

© 1998 - 2011 Terry Wickenden TKW Design Site developed, maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.