Sort Table by Field

  • Thread starter edisonl via AccessMonster.com
  • Start date
E

edisonl via AccessMonster.com

Hi,

1. I have a form that diaply all data from a table tblperson,

2. Would like to have a control to sort the document eg: employdate, name,
date of birth.

3. Where should I insert the code ?

4. sorting result diaply within the table itself, result still be able to
edit by user.

Regards & God Bless, Edison
 
D

Dorian

May I ask why you need to sort the table?
Are you expecting to be able to save the table in its sorted state?
If you need to sort to be able to locate records, there is a better way of
achieving that. You can create a find command to be able to locate records by
the value in any field.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
E

edisonl via AccessMonster.com

Hi Drorian,

thanks for your reply.. I need to be able to update as they edit.
firstly there is an ongoing changing of data in table but not through backend
data.

Regard & God Bless
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~ ~ ~ ~ ~
May I ask why you need to sort the table?
Are you expecting to be able to save the table in its sorted state?
If you need to sort to be able to locate records, there is a better way of
achieving that. You can create a find command to be able to locate records by
the value in any field.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
[quoted text clipped - 9 lines]
Regards & God Bless, Edison
 
A

AccessVandal via AccessMonster.com

Simply create a button to sort the OrderBy filter on your form or sort it the
open/load event, never set it on the table.

Example.

Private Sub Button0_click()
me.orderby = "control or field"
me.orderbyon = True
End sub

Example:

1. me.orderby = "Field1 ASC"
2. me.orderby = "Field1 DESC"
3. me.orderby = "Field1 ASC, Field2 DESC"
 
J

John W. Vinson

Hi,

1. I have a form that diaply all data from a table tblperson,

2. Would like to have a control to sort the document eg: employdate, name,
date of birth.

Access doesn't have "documents".

Are you using the word "sort" correctly? To SORT means to put a set of records
in a particular sequential order. It's often misused to mean search or select.
Is that what you want to do? Or do you want to sort the records on the form
sequentially by (the user's choice of) employdate, name, birthdate?
3. Where should I insert the code ?

No code is needed.
4. sorting result diaply within the table itself, result still be able to
edit by user.

Tables *store data*. They don't display it. They also aren't sorted; a Table
should be viewed as an unordered heap of records.

If you want to sort data, use a Query based on the table, with a sort
specified in the query. You can base a Form on a sorted query, and it will
still be updateable. You can also use the Form's OrderBy property with code
(if you want to do the dynamic sorting mentioned above).
 
M

Marshall Barton

edisonl said:
1. I have a form that diaply all data from a table tblperson,

2. Would like to have a control to sort the document eg: employdate, name,
date of birth.

3. Where should I insert the code ?

4. sorting result diaply within the table itself, result still be able to
edit by user.


Uswe the control's AfterUpdate event to set the form's
OrderBy property to the name of the sort field.

Without knowing what kind of control you want to do all
this, I can't suggest any specific code.

Tables can not be sorted, they are just a bag of records.
The **ONLY** way to sort data is by using a query with an
ORDER BY clause. A form's OrderBy property is one way to
specify the form's record source sorting (via an Access
generated query).
 
E

edisonl via AccessMonster.com

Hi AccessVandal,

Right will try it out ... Thanks AccessVandal. :)

Regards & God Bless, Ediaon
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
Simply create a button to sort the OrderBy filter on your form or sort it the
open/load event, never set it on the table.

Example.

Private Sub Button0_click()
me.orderby = "control or field"
me.orderbyon = True
End sub

Example:

1. me.orderby = "Field1 ASC"
2. me.orderby = "Field1 DESC"
3. me.orderby = "Field1 ASC, Field2 DESC"
[quoted text clipped - 9 lines]
Regards & God Bless, Edison
 
E

edisonl via AccessMonster.com

Hi AccessVandal,

I tried & it works.. thanks..

HOWever, can i sort base on 2 or more criteria ?
Eg:
OrderBy = "Name" + "Gender" ?

I tried execute but got nothing in the end.

Regards & God Bless, Edison
 
A

AccessVandal via AccessMonster.com

Didn't this work?

3. me.orderby = "Field1 ASC, Field2 DESC"

You can't use the "+" character, use the comma instead like

OrderBy = "Name, Gender"

Please note that "Name" is a reserved word in Access, rename it to something
else if it's possible else use the square bracket "[Name]".
 
E

edisonl via AccessMonster.com

Hi AccessVandal,

You are fast.. thanks Man.. & it WORKS !

Regards & God Bless
 

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