A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Order By not working when record source set by vba



 
 
Thread Tools Display Modes
  #1  
Old February 13th, 2010, 08:31 AM posted to microsoft.public.access.forms
Mat Child
external usenet poster
 
Posts: 14
Default Order By not working when record source set by vba

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

  #2  
Old February 13th, 2010, 08:41 AM posted to microsoft.public.access.forms
Mat Child
external usenet poster
 
Posts: 14
Default Order By not working when record source set by vba

BTW - This was written for access 2003, but does exactly the same in 2007

"Mat Child" wrote:

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

  #3  
Old February 13th, 2010, 04:52 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Order By not working when record source set by vba

On Sat, 13 Feb 2010 00:31:01 -0800, Mat Child
wrote:

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.
--

John W. Vinson [MVP]
  #4  
Old February 13th, 2010, 09:12 PM posted to microsoft.public.access.forms
Mat Child
external usenet poster
 
Posts: 14
Default Order By not working when record source set by vba

Brilliant, that was the missing link

Thank you very much

Mat

"John W. Vinson" wrote:

On Sat, 13 Feb 2010 00:31:01 -0800, Mat Child
wrote:

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.
--

John W. Vinson [MVP]
.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.