Sorting a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using ACCESS 97.

I have created a form from a table but for some reason it doesn't populate
the form until I press the sort acsending button on the toolbar. The table
is sorted correctly.

Can anyone assist me with some code which sorts it before the form is
opened to pevent this happening , please?


Many thanks
 
Mark said:
I am using ACCESS 97.

I have created a form from a table but for some reason it doesn't populate
the form until I press the sort acsending button on the toolbar. The table
is sorted correctly.


You have a misunderstanding here. Tables are not sorted in
any way. If you see the records in an order you like, it's
just a coincendence and will probably not stay that way in
the future.

To sort the records in a form, you **must** use a query with
an Order By clause as the form's RecordSource property. The
RecordSource property does give you the option of using a
saved query name or an SQL statement.

Using an SQL statement can make it very easy for you to fix
your specific problem by changing the form's RecordSource
from:
tablename
to
SELECT * FROM tablename ORDER BY sortfieldname
 
I am using ACCESS 97.

I have created a form from a table but for some reason it doesn't populate
the form until I press the sort acsending button on the toolbar. The table
is sorted correctly.

Can anyone assist me with some code which sorts it before the form is
opened to pevent this happening , please?

Basic misconception here: A Table cannot be "sorted". It's an
unordered "heap" of data. A table datasheet can be sorted for display
purposes, but that does not affect how the data is stored; Access
actually creates a hidden Query to sort the data for you.

Rather than basing your Form directly on the Table, create a Query
based on the table; specify the sort order in the Query. The Form will
now display records in that order, and you'll be able to edit the data
and do anything you can do with the Table.

John W. Vinson[MVP]
 
Back
Top