populate form with query results

mitchem1

Registered User.
Local time
Today, 08:51
Joined
Feb 21, 2002
Messages
153
After the form is already open, our users want to sort on a text field that is a combination of numbers and text. They want the sort in descending order with 7L-1500A above 7L-856, etc. I have created a query with a rather complex expression that will accomplish the sort correctly. I have a button on the form that fires the query. My question is this. Is there a way to then repopulate the form with the query results so that the user gets the records in the order they desire? Thank you.
 
If you've sorted the query correctly, you can use it to feed the form. Then in the form, set the OrderBy property equal to the field name. Use some code like:
Me.OrderBy="your_field_name"
Me.OrderByOn=True
 
Thanks. As you can tell, I'm not a programmer at all, so if you can bare with me...
What I've got is a button on the form. When clicked now, it actually opens the query window. The query results are exactly what I need.
But, in a perfect world, when the user would click the button, the query window would not display but would instead run in the back ground and then the form would be repopulated with the query results. Is this possible? Thanks again.
 
To set the records that feed into a form, you can programatically set the form's recordsource property. You can set it to the name of a table, name of a query, or a SQL statement. It's best to use a query if you want to sort the results - no coding required.

If you want to set the recordsource when the form is already open, you'll need to run some VBA code. You can attach the code to a command button or to an event. The code will be something like:
Me.RecordSource="queryname"
Replace "queryname" with the actual name of your query.

If the form is already being fed by the proper query and you just want to resort the results, then you'd use that code I initially posted.
 

Users who are viewing this thread

Back
Top Bottom