473,385 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing the OrderBy of a subform programatically

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

✓ answered by sierra7

Instead of Me.Refresh try;
Expand|Select|Wrap|Line Numbers
  1. Me.OrderByOn = True
Works for me!
S7

6 6396
TheSmileyCoder
2,322 Expert Mod 2GB
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
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 Expert 256MB
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 Expert Mod 2GB
I would try to start with testing Sierra7's suggestion.

To refer to the parent form you use Me.Parent.
Nov 17 '11 #5
Brilliant, that works! Thanks to sierra7 and TheSmileyCoder!
Nov 17 '11 #6
NeoPa
32,556 Expert Mod 16PB
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.