Order By not working when record source set by vba

M

Mat Child

I had a continuous form in my database which was bound to 1 query and
filtered it based on combo box values.
All the fields (apart from the combos) where locked and disabled to make
them view only.
The form also had labels for each of the columns and if you clicked it, vba
code would order the form by that column's data, click another label and it
would orderby that column instead.

All was fine until i decided that it would be more efficent if the form used
different queries for each of the criteria instead of holding all the records
in memory and filtering them.
That feature works fine, the vba code changes the record source according to
the option selected, but the Orderby feature no longer works.
If I put the form into design view and back again it retains the recordset
it had previously and the orderby feature works.

What Am i missing? Clearly when the record source is set by VBA something is
upsetting the orderby.

Any help would be appreciated.

Example of what i use to sort by the REL_Staus field is

Me.OrderBy = "REL_status"

and changing the record source is

Me.RecordSource = "REL_ByUser_Running"


Thanks

Mat
 
J

John W. Vinson

What Am i missing? Clearly when the record source is set by VBA something is
upsetting the orderby.

Any help would be appreciated.

Example of what i use to sort by the REL_Staus field is

Me.OrderBy = "REL_status"

What you're missing is that you must *also* set the form's OrderByOn option to
True:

Me.OrderByOn = True

This property is off by default.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top