• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 675
  • Last Modified:

Change sort order on a sub-form in VBA

I have a form that users copy/paste directly into.  The source data comes from another application that spits out in Excel.  The user then highligyhts the area needed and copies this directly into the sub-form (for various reasons, cannot upload).  So, now the data is in the sub-form, but I need a way for the user to be able to sort via a command button by Branch Number either ascendig or descending. Since there is no query or an open event, I cannot use these so must resort to a button.  I got as far as the OrderBy, but that does not work.  I simply want the data on the sub-form sorted either direction when the user hits the sort button.
Private Sub cmdBranchSort_Click()
    Me.sfmAMLItems.Form.OrderBy
End Sub

Open in new window

0
ssmith94015
Asked:
ssmith94015
  • 2
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Private Sub cmdBranchSort_Click()

    Me.sfmAMLItems.Form.OrderBy = "SomeFieldName"
    Me.sfmAMLItems.Form.OrderByOn = True

End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Or

Me.sfmAMLItems.Form.OrderBy = "SomeFieldName DESC"

You either need two buttons (Asc or Desc) ... or ... retain the previous state and toggle it.  I would suggest two buttons.

mx
0
 
ssmith94015Author Commented:
DatabaseMX works but now that the data is in ascending, would I set the OrderByOn = False?  Think I will go try that and see what happens.
0
 
ssmith94015Author Commented:
Works, used the toggle as I am cramped for space.  As it toggles, the caption changes so the user knows which direction he is going.

Thank you.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now