Full Version: Using ORDER BY with subform
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
fergie5
Is there a certain way to use ORDER BY in a subform? I have tried entering the name of the field that I want to ORDER BY in the main form, subform, Form!MainForm!Field, Form!Main!Subform!Field, etc. and I cannot get it to work. The field I want to Order is located in the subform. It does not matter if the main form is ordered or not. Is there any solution to this problem?

Ryan
ChrisLeClark
Hi Ryan
This is how I would do it but it's just what I experience.

Go to the recordsource property for the subform and enter your cursor in the recordsource property field perhaps after the table/query name.
Note the epillipse (...) that appears to the right of the recordsource property, and click on it, you may get a message prompt, click ok and a query grid will open up.
Sort on the desired field as required.
Close the query and click yes at the prompt to save the SQL changes.
Now immediately save the form using the save icon or file>save or you will lose the SQL changes you just made.
Now your subform should be sorted.

hth
Chris
fergie5
Thanks for the help. I wonder why it works with the query and not the ORDER BY property? Oh Well, I appreciate your help.

Ryan
ChrisLeClark
Hi Ryan
Its a strange one. I found another webpost on the issue which says.....

You have to define the orderby of the sub-form in the main form.

Set the OrderBy (and set OrderByOn to true) for the subform in the
OnOpen or OnCurrent event of the main form. Something like:


Me![name of subform control].form.OrderBy = "field you want to sort on"
Me![name of subform control].form.OrderByOn = True

But I have no experience of using this - just might be interesting for you to check it out.

Chris
fergie5
Thanks Chris.
ChrisLeClark
No probs......
Glad to help.

Chris wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.