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!

How to sort a datasheet subform from button on main form 1

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
I have a form with a datasheet subform on it. I can sort the datasheet on the values in one of the columns by clicking on the column and then clicking on the sort ascending icons in the task bar. I would like to put a button on the main form that would do the same thing. So what code would I put behind the button and what event would I use to sort a column on a datasheet view subform from the main form.
 
How are ya projecttoday . . .

Try:
Code:
[blue]   docmd.RunCommand acCmdSortAscending[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The thing is it's on the main form. And I need to sort on the selected row.
 
Correction: The thing is it's on the main form. And I need to sort on the selected column.
 
here is a demo with two buttons on the main form. One Sorts by a field (isEvent) the other sorts by startDate and then isEvent

Code:
Public Sub sortSubForm(strFldname As String)
  Dim frm As Access.Form
  Set frm = Me.mySubForm.Form
  With frm
    .OrderBy = strFldname
    .OrderByOn = True
  End With
End Sub

Private Sub cmdSortDateEvent_Click()
  sortSubForm ("startDate, isEvent")
End Sub

Private Sub cmdSortEvent_Click()
  sortSubForm ("isEvent")
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top