Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command button to sort columns

Status
Not open for further replies.

tizwaz

Technical User
Aug 8, 2002
437
GB
I want to put a series of command buttons on a continuous form so that if you click the button at the top of the column it sorts it in ascending order ( and possibly if you click it a second time) it sorts it in descending order) - can this be done?
 
Have a look at the OrderBy and OrderByOn properties of the Form object.
The buttons must be in the Header section of the continuous form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You can
[tt]
Me.FieldName.SetFocus
DoCmd.RunCommand.accmdSortAscending.[/tt]

doing it with if statement will do descending too.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
I've got it working for sorting ascending using on a command button in the form header for each column
Me.Extension.SetFocus
DoCmd.RunCommand acCmdSortAscending

How could I make the add the code for Sort Ascending apply if you clicked the same button a second time (ie each time you click a button it sorts it the other way)
 
Good morning,
I was away after my post..
Here are the solutions I know. May be more with others.
Two ways...
first one to store the sort order as public variable then sort it.
Code:
Option Compare Database
Option Explicit
Public sortorder
'-------------------------------------------------

Private Sub MyTextbox_Label_Click()
    Me.MyTextbox.SetFocus
    If sortorder = "Z to A" Or sortorder = "" Then
        DoCmd.RunCommand acCmdSortDescending
        sortorder = "A to Z"
    Else
        If sortorder = "A to Z" Then
            DoCmd.RunCommand acCmdSortAscending
            sortorder = "Z to A"
        End If
    End If
End Sub

'---------------------------------------------------

Else set the command button's caption to a-z or z-a.
Code:
'---------------------------------------------------
Private Sub cmdSort_Click()
    Me.MyTextbox.SetFocus
    If Me.cmdSort.Caption = "A to Z" Then
        DoCmd.RunCommand acCmdSortDescending
        Me.cmdSort.Caption = "Z to A"
    Else
        DoCmd.RunCommand acCmdSortAscending
        Me.cmdSort.Caption = "A to Z"
    End If
End Sub
'---------------------------------------------------

May be setting the tag property to public variable also will do the same as the first sample.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Thanks v much - have used the 1st method and it's working great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top