473,399 Members | 2,146 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,399 software developers and data experts.

How to sort records in a subform control?

MLH
I have created two forms: frmBrowseNegsMainform and
frmBrowseNegsSubform. I put a subform control on the
first of these. The SourceObject property for the subform
control is, of course, frmBrowseNegsSubform.

I would like to perform an ascending or descending sort
on any of the 7 columns shown in datasheet view in the
subform control. I've been unsuccessful.

Is there something tricky about sorting in subform controls?
Nov 13 '05 #1
12 18964
Use command buttons for the column headings and in the Click event of each
button, set the OrderByOn property to True, the OrderBy property to the name of
the field under the button and requery the form.

Note: You can use labels also because they have a Click event but buttons make
it look like they can be clicked.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"MLH" <CR**@NorthState.net> wrote in message
news:br********************************@4ax.com...
I have created two forms: frmBrowseNegsMainform and
frmBrowseNegsSubform. I put a subform control on the
first of these. The SourceObject property for the subform
control is, of course, frmBrowseNegsSubform.

I would like to perform an ascending or descending sort
on any of the 7 columns shown in datasheet view in the
subform control. I've been unsuccessful.

Is there something tricky about sorting in subform controls?

Nov 13 '05 #2
MLH
I neglected to mention the problem is in Access 2.0, which supports
no OrderBy or OrderByOn properties. Please excuse.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx

On Sun, 25 Jul 2004 00:11:49 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
Use command buttons for the column headings and in the Click event of each
button, set the OrderByOn property to True, the OrderBy property to the name of
the field under the button and requery the form.

Note: You can use labels also because they have a Click event but buttons make
it look like they can be clicked.


Nov 13 '05 #3

"MLH" <CR**@NorthState.net> wrote in message
news:7i********************************@4ax.com...
I neglected to mention the problem is in Access 2.0, which supports
no OrderBy or OrderByOn properties. Please excuse.


That's pretty funny. You're excused!
Nov 13 '05 #4
I have never used Access 2.0 so don't know if this is available! Another way to
do it is to create the same command buttons (or use labels) and code each to
build a querydef on the fly. You would then requery the form.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"MLH" <CR**@NorthState.net> wrote in message
news:7i********************************@4ax.com...
I neglected to mention the problem is in Access 2.0, which supports
no OrderBy or OrderByOn properties. Please excuse.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx

On Sun, 25 Jul 2004 00:11:49 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
Use command buttons for the column headings and in the Click event of each
button, set the OrderByOn property to True, the OrderBy property to the name ofthe field under the button and requery the form.

Note: You can use labels also because they have a Click event but buttons makeit look like they can be clicked.

Nov 13 '05 #5
"MLH" wrote
I neglected to mention the problem is in Access 2.0, which supports
no OrderBy or OrderByOn properties. Please excuse.


Have you tried replacing the RecordSource of the Form with an SQL Statement
that includes a different ORDER BY clause? I'm quite certain that Access
2.0's Jet SQL includes the clause.

Access 2.0 was and is a good, small-footprint database and database
development tool -- later versions did, or course, add features and
functions, and patched up the 'worst' hole in Access 2.0 security.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #6
MLH
Yes, Larry, I did try that. I opened the actual subform in datasheet
view and verified that when I replaced the RecordSource of the
Form with an SQL statement having a different ORDER BY clause.
The sort order on the actual subform DID change as intended. But
nothing I did could make the changes show up in the subform control.

Do you think I can open the actual subform in design view, modify
the RecordSource property and save it with the new settings - all
from within code? I believe, if I do that, then requery the subform
control, I'll get what I want. Lets see...

DoCmd OpenForm "frmBrowseNegsSubform", A_DESIGN
MySQL = "blah blah blah"
Forms!frmBrowseNegsSubform.RecordSource = MySQL
Hmmm??? What command line would save the form & the changes???
Me!MySubformControl.Requery

Think that'll work?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
On Sun, 25 Jul 2004 01:20:07 GMT, "Larry Linson"
<bo*****@localhost.not> wrote:
"MLH" wrote
I neglected to mention the problem is in Access 2.0, which supports
no OrderBy or OrderByOn properties. Please excuse.


Have you tried replacing the RecordSource of the Form with an SQL Statement
that includes a different ORDER BY clause? I'm quite certain that Access
2.0's Jet SQL includes the clause.

Access 2.0 was and is a good, small-footprint database and database
development tool -- later versions did, or course, add features and
functions, and patched up the 'worst' hole in Access 2.0 security.

Larry Linson
Microsoft Access MVP


Nov 13 '05 #7
MLH
Damn! The code below didn't work either. I could open the actual
subform in design mode easily enough, make the changes, close
the form, saving the changes on the way out. But neither the Requery
Action nor the Requery Method would rearranget the records already
displayed in the subform control. I even put a DoEvents statement
prior to the Requery Action/Method. The only thing that works is
closing the main form and reopening it. The subform control then
displays the records in the newly sorted order. But there's just no
way I'm gonna implement that as a strategy. I'm stuck here!
DoCmd OpenForm "frmBrowseNegsSubform", A_DESIGN
MySQL = "blah blah blah"
Forms!frmBrowseNegsSubform.RecordSource = MySQL
Hmmm??? What command line would save the form & the changes???
Me!MySubformControl.Requery


Nov 13 '05 #8
> >Forms!frmBrowseNegsSubform.RecordSource = MySQL

Two problems here:
1. A subform is not part of the Forms collection; it belongs to the main form's
collection. You need to reference the subform like this:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form

2. A subform control does not have a recordsource property! The form in the
subform control does though. Try:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form.Rec ordSource = MySQL
Me!MySubformControl.Requery
You can't requery a subform control either but again you can requery the form
the control holds:
Me!MySubformControl.Form.Requery
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"MLH" <CR**@NorthState.net> wrote in message
news:93********************************@4ax.com... Damn! The code below didn't work either. I could open the actual
subform in design mode easily enough, make the changes, close
the form, saving the changes on the way out. But neither the Requery
Action nor the Requery Method would rearranget the records already
displayed in the subform control. I even put a DoEvents statement
prior to the Requery Action/Method. The only thing that works is
closing the main form and reopening it. The subform control then
displays the records in the newly sorted order. But there's just no
way I'm gonna implement that as a strategy. I'm stuck here!
DoCmd OpenForm "frmBrowseNegsSubform", A_DESIGN
MySQL = "blah blah blah"
Forms!frmBrowseNegsSubform.RecordSource = MySQL
Hmmm??? What command line would save the form & the changes???
Me!MySubformControl.Requery

Nov 13 '05 #9
MLH
Thanks for the tip, PCD. I'll give it a try. At this point, all I've
tried has gotten me nowhere. I did look up this Access 2.0
help blurb. It seems to suggest that I can use the Requery
method with subform controls. But I'm not having any luck...
Requery Method
See Also Example 2.0

Applies To
Forms. Controls (combo boxes, list boxes, subforms/subreports).

Description

Updates the data in a specified form or in a control that is on the
active object by requerying the source of data of the form or control.

Syntax
objectname.Requery

Argument Description
objectname The name of the form or control you want to update.
Omit this argument to requery the source of data of the active object.

Remarks

Use this method to ensure that the form or control displays the most
recent data. The Requery method does one of the following:

Reruns the query on which the form or control is based.
Displays any new or changed records or removes deleted records
from the table on which the form or control is based.

Controls based on a query or table include:

List boxes and combo boxes
Subform controls
OLE objects, such as graphs
Controls containing aggregate functions such as DSum

If the specified control isn't bound to a field in a table or query,
this method forces a recalculation of the control.
If you omit objectname, the Requery method has the same effect as
pressing SHIFT+F9 when a form or control has the focus (it requeries
the underlying tables). If a subform control has the focus, this
method requeries only the source of data of the subform.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sun, 25 Jul 2004 02:17:21 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
>Forms!frmBrowseNegsSubform.RecordSource = MySQL
Two problems here:
1. A subform is not part of the Forms collection; it belongs to the main form's
collection. You need to reference the subform like this:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form

2. A subform control does not have a recordsource property! The form in the
subform control does though. Try:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form.Re cordSource = MySQL
>Me!MySubformControl.Requery

You can't requery a subform control either but again you can requery the form
the control holds:
Me!MySubformControl.Form.Requery


Nov 13 '05 #10
MLH
Sigh! No relief in sight. I'm having no trouble at all when
it comes to manipulating the subform itself. Its the subform
control on the main form that isn't cooperating. I'm still in
the same boat - the only way I can see the new sort order
in the subform control on the main form is to close and
reopen the main form. I cannot seem to light a fire under
the subform control - nothing seems to work.

Its funny, I have another main form with a subform control
in the very same application. I get exactly what I want there
I created 2 subforms and I switch the subform control's
SourceObject Property setting to point to either of the
desired subforms, then I run this line...

Me![frmOnHoldAdministratorSub].Requery

from a command button on the main form and I get EXACTLY
what I want. In the above line, Me!frmOnHoldAdministratorSub
refers to the subform control on the main form. The Requery
Method works just fine there, but not in my other form. Heck!

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx

On Sun, 25 Jul 2004 02:17:21 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
>Forms!frmBrowseNegsSubform.RecordSource = MySQL
Two problems here:
1. A subform is not part of the Forms collection; it belongs to the main form's
collection. You need to reference the subform like this:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form

2. A subform control does not have a recordsource property! The form in the
subform control does though. Try:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form.Re cordSource = MySQL
>Me!MySubformControl.Requery

You can't requery a subform control either but again you can requery the form
the control holds:
Me!MySubformControl.Form.Requery


Nov 13 '05 #11
I'm sorry I didn't make myself clear... you don't need to open the Form
embedded in the Subform Control in Design View, you can change the
RecordSource at runtime. Assume that on the Form embedded in the Subform
Control, you have two Buttons... one for Sort by Ascending JobCode and the
other Sort by Descending JobCode, and that the RecordSource is a Query
pulling selected fields from tblJobTable (a copy of which, without any
sorting, is stored in the Form-level variable strSQL of the Form embedded in
the Subform Control).

In the button click event for the first button

Me.RecordSource = strSQL & " ORDER BY JobCode ASC"

In the button click event for the second button

Me.RecordSource = strSQL & " ORDER BY JobCode DESC"

These settings will last until you change them by clicking the other button
or until you close the Form (by closing the main Form that contains the
Subform control in which this Form is displayed). They will not be preserved
until the next time the Form or the Database is Opened.

If you put those buttons on the main form, then the reference, as PC
Datasheet explained, is a little more complex.

Larry Linson
Microsoft Access MVP

"MLH" <CR**@NorthState.net> wrote in message
news:07********************************@4ax.com...
Sigh! No relief in sight. I'm having no trouble at all when
it comes to manipulating the subform itself. Its the subform
control on the main form that isn't cooperating. I'm still in
the same boat - the only way I can see the new sort order
in the subform control on the main form is to close and
reopen the main form. I cannot seem to light a fire under
the subform control - nothing seems to work.

Its funny, I have another main form with a subform control
in the very same application. I get exactly what I want there
I created 2 subforms and I switch the subform control's
SourceObject Property setting to point to either of the
desired subforms, then I run this line...

Me![frmOnHoldAdministratorSub].Requery

from a command button on the main form and I get EXACTLY
what I want. In the above line, Me!frmOnHoldAdministratorSub
refers to the subform control on the main form. The Requery
Method works just fine there, but not in my other form. Heck!

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx

On Sun, 25 Jul 2004 02:17:21 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
>Forms!frmBrowseNegsSubform.RecordSource = MySQL


Two problems here:
1. A subform is not part of the Forms collection; it belongs to the main form'scollection. You need to reference the subform like this:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form

2. A subform control does not have a recordsource property! The form in thesubform control does though. Try:
Forms!NameOfMainForm!frmBrowseNegsSubform.Form.Re cordSource = MySQL
>Me!MySubformControl.Requery

You can't requery a subform control either but again you can requery the formthe control holds:
Me!MySubformControl.Form.Requery

Nov 13 '05 #12
gn
On Sat, 24 Jul 2004 23:39:22 -0400, MLH <CR**@NorthState.net> wrote:
Sigh! No relief in sight. I'm having no trouble at all when
it comes to manipulating the subform itself. Its the subform
control on the main form that isn't cooperating. I'm still in
the same boat - the only way I can see the new sort order
in the subform control on the main form is to close and
reopen the main form. I cannot seem to light a fire under


Why not with code close the form and reopen so fast no one notices
Nov 13 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sabine Oebbecke | last post by:
Hi Experts! I have several forms and reports where controls get their values with 'Forms!MainForm!Control' or 'Forms!MainForm!Subform!Control' resp 'Forms!MainForm!Subform.Form!Control' which...
3
by: Melissa | last post by:
I have forty-two small subforms on a form. I need help with the code that will return the name of the subform control when I click on any subform control. I know how to select all the subform...
10
by: Sally | last post by:
When I click on a control in a subform, what is the syntax to return the name of the subform control on the main form that contains the subform? MsgBox "MySubform is in " & < ???? > Thanks, ...
4
by: MLH | last post by:
I have a subform control on a mainform. Each time I do anything experimentally with it - like even change its Width property, A97 takes the liberty of setting values in the link child field and...
6
by: MLH | last post by:
When the vehicle entry form (frmVehicleEntryForm) first opens, the additional owner SubForm control (frmAddnlOwnrListSubForm) is enabled. You can click on it and it will accept the focus. But after...
1
by: MLH | last post by:
I have a form with a subform control on it listing records returned by a saved query named UnbilledVehicles. I would like to put command buttons on the main form to apply dynamic filters to the...
3
by: ApexData | last post by:
I am using the Shortcut Menu Bar property of many combobox controls to execute a single shared custom function. When the function executes, I need it to immediately identify the following items:...
1
by: veteranwebdesign | last post by:
Hello, I have a main form. I want forms to open in a subform control box. What is the code for the option group to open the subforms in the control box. I didn't create subforms, I created...
4
by: MLH | last post by:
If I have a main form - Form3 - with a subform control named SF4 and they are NOT linked on any common field (no child or master field links) - can I write code on Form3 to filter the records...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...

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.