473,492 Members | 4,279 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Changing the OrderBy of a subform programatically

4 New Member
I have a Form with a (Continuous) Subform that lists the results of a query. There's a header within the Subform that has several elements you can click on to programatticaly change the OrderBy of the Subform then refresh it. An example of the code I use is here:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CompanySort_Click()
  2. If (Me.OrderBy = "Company") Then
  3. Me.OrderBy = "Company DESC"
  4. Else
  5. Me.OrderBy = "Company"
  6. End If
  7. Me.Refresh
  8. End Sub
This works fine when the Form (which is named "Results Subform") is run by itself, but doesn't work when run as part of the parent Form ("Results"). The name of the Subform control is "Report subform", can't remember why it's different now...

What am I doing wrong? I'm sure it's simple, but I'm stumped, any help is much appreciated.
Nov 17 '11 #1
6 6409
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im not really sure why that is happening.

First off, are you sure the code is running? Have you tried stepping through it?
Nov 17 '11 #2
ojeffery
4 New Member
Thanks for your reply. Yes, code appears to be running - I've tried putting msgboxes after each significant bit of code to check, which still come up. It works fine when the "Results Subform" is open as a form in itself, but not when it's a subform. Could it be that "me" is referring to the parent rather than the subform?
Nov 17 '11 #3
sierra7
446 Recognized Expert Contributor
Instead of Me.Refresh try;
Expand|Select|Wrap|Line Numbers
  1. Me.OrderByOn = True
Works for me!
S7
Nov 17 '11 #4
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I would try to start with testing Sierra7's suggestion.

To refer to the parent form you use Me.Parent.
Nov 17 '11 #5
ojeffery
4 New Member
Brilliant, that works! Thanks to sierra7 and TheSmileyCoder!
Nov 17 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Setting Me.OrderByOn = True certainly works when it wasn't previously set, but if you find it doesn't when changing from one sort order to another (In other words it works only for the first change - Help doesn't specify and I don't have time to set up a test myself) then a .Requery call should do it for you.
Nov 17 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4064
by: Deano | last post by:
Hi, I was just setting up a test system on a client's machine yesterday and as ever noticed a few problems. One that has thrown me is to do with the order of records in a subform (datasheet...
6
6873
by: P. Emigh | last post by:
By default in more recent versions, Access forms keep users' last sort request in the "orderby" property. That can slow things down considerably, especially when the last user has chosen a...
2
6142
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box...
0
2105
by: Ace Calhoon | last post by:
Hello, Using Access 2003 SP-1. I have a form which contains a subform. Each form represents a table, and is linked by two fields. These fields are also related in the underlying tables, with...
6
1697
by: Maximus | last post by:
Hi everybody, Has anyone changed the session state in web.config programatically through the applications. Any Help will be appreciated. Thanks.
4
2625
by: vidiot | last post by:
I am trying to create a subform that will display images related to the parent form. The subform is a continuous form as there will be several images that relate to the parent form. I checked...
1
1179
by: sparks | last post by:
I am trying to change a subform in access 2003 based on what is selected in a combobox But to change the subform I would have to do something like Me.subformOPS change sourse object to...
8
5160
by: NJonge01 | last post by:
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes...
0
1034
by: slinky | last post by:
I have a subform (called subProjects) found on a tab (called Page255) on a form (called Main Menu) for which I want to change the Edit, Delete, Add properies. What looks wrong with this code that...
19
4947
by: postman | last post by:
I have a parent form bound to a recordsource and several controls are bound to fields in that recordsource. There are also several unbound controls that are used to display various data in a...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.