Code Examples For RunCommand Constants

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 ********************