Code Examples

Sort A Field In Ascending Order

acCmdSortAscending

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

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

Sub cmdSortAsc_Click()
  On Error Goto ErrHandler
  Screen.PreviousControl.SetFocus
  DoCmd.RunCommand acCmdSortAscending
  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.