Sort datasheet subform by column with command button on main form

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
 
J

John W. Vinson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top