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

Sandra SmithRetiredAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Private Sub cmdBranchSort_Click()

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

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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
Sandra SmithRetiredAuthor 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
Sandra SmithRetiredAuthor 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.