change sort order of table

AmberO

Registered User.
Local time
Today, 14:41
Joined
May 9, 2002
Messages
27
Is it possible to sort a table by a particular field using vb code? I tried using order by, but can't get the syntax correct.

(I know I can use a query, but I need to sort the actual table).

Thank you!

Amber
 
How are you viewing the Table? (Directly/Form/Report)

If it is from a form make sure that any field names that have spaces are inclosed in brackets [ ].

If it is from a report, look at the Sorting and Grouping options (This overrides query and report properties sort orders)
 
Thanks for the reply,

Actually I am not viewing the table - I am trying to change the sort order of the table from code that is called from a button on an unbound form.

I am using access to import data from text files, manipulate it (add columns, change certain fields and sort orders) and then print out reports - which is why I need to be able to change the table directly...any ideas?
 
Amber,

If the code behind the button references a query
you can change the sort order in the queries
design view.

If it has a hard-coded SQL statement then you
need:

Select ...
From ...
Where ...
Order by Field1 Asc, Field2 Desc

hth,
Wayne
 
Should I take it that it is impossible to change the sort order of a table directly using code then?

I know I can do it by clicking on the A-Z button on the toolbar, which is why I thought there must be another way

Thanks for the response though!
 
When you open the table through code to manipulate it I'm assuming your using a recordset, if so use an ORDER BY method in the SQL statement followed by the field names of the sort order.

strSQL = "SELECT * FROM MyTable ORDER BY [Field1], [Field2]"

for when you run your report, you should set the same fields in the "ORDER BY" property and don't forget to turn the "Order By On" property to Yes
 
Thank you

Calvin,

This is the second time today that you have really helped me out. Thank you so much! That is just what I was looking for.

Amber
 

Users who are viewing this thread

Back
Top Bottom