OrderBy on SubForm doesn't sort records

The AllowFilter property of the subform is set to "Yes".  The subform's RecordSource property points to a query that has "CBEQ" as one of the cols.  The form's OnOrder property is "CBEQ DESC".

The rows don't display in CBEQ DESC order.  

 I know I can add the sort to the query, but different cols can be selected by a control on the main form and thus change the displayed sort order.  So I need to be able to change the reference in the OnOrder.

The form in its saved state has the OnOrder property set as described above and after opening the form the records aren't displaying in the correct order.   I tried leaving off the DESC, but it still displays in the same order.

Any suggestions of how to fix this problem?
Who is Participating?
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:
Try this in code:

Private Sub Form_Load()

me.OrderBy =  "CBEQ DESC"
Me.OrderByOn = True                 '*** you need this

End Sub

katzwhiteAuthor Commented:
I don't see an OrderByOn property in either the main form or the subform.  I only have record source, Filter, Order By & Allow Filters.. In both forms the Allow filters property is set to Yes

I'm not using VBA on the initial opening fo the form as the default sort is set per the subforms properties.  This isn't working.  When I get this to work, I'll try the VBA  to allow different sort orders.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"I don't see an OrderByOn property in either the main form or the subform."

That property is not on the Property sheet.  From the Help File:

"For reports, the OrderByOn property must be set to Yes to apply the sort order specified by the object's OrderBy property.

**For forms, select the field by which you want to sort the records and either click the appropriate Sort button on the toolbar, or point to Sort on the Records menu and click the appropriate command on the submenu. ***** You can also set the OrderByOn property for either forms or reports by using Visual Basic."

AFAIK ... you will need to set the OrderByOn property in code.  That's the only way I've got it to work.


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
katzwhiteAuthor Commented:
I had read the Help, but somehow decided "OrderByOn" was for reports only since I couldn't find it on the form property sheet.  Thanks for the assist.

Best wishes
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
you are welcome.  

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 Access

From novice to tech pro — start learning today.