Sort datasheet subform by column with command button on main form

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

What code could I put in a command button's on click event that would make a
datasheet subform sort by a selected column? I have a form with a datasheet
subform on it. If you select a column and click on the sort assending icon
in the task bar, it sorts. I want to do the exact same thing but I want it
to be done from a button. The button is on the main form. The datasheet is
the subform. How would I do this?

Robert
 
What code could I put in a command button's on click event that would make a
datasheet subform sort by a selected column? I have a form with a datasheet
subform on it. If you select a column and click on the sort assending icon
in the task bar, it sorts. I want to do the exact same thing but I want it
to be done from a button. The button is on the main form. The datasheet is
the subform. How would I do this?

Robert

How does the button know WHICH field to sort by?

You'ld set the subform's OrderBy property:

Private Sub cmdSortLastname_Click()
Me.subMySubform.Form.OrderBy = "[LastName]"
Me.subMySubform.Form.OrderByOn = True
Me.subMySubform.Requery
End Sub
 
Back
Top