Hello,
I am looking for a good way to permanently sort a table in Access. The
way i have below works but i was wondering if there is a better and
faster way.
Kind regards,
Alex
'-------------------------------------------
Public Sub Sort()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rst2 As New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.CursorLocation = adUseClient
rst2.CursorType = adOpenDynamic
rst2.LockType = adLockOptimistic
rst2.CursorLocation = adUseClient
Set cnn = CurrentProject.Connection
rst.Open "SELECT * FROM Table1", cnn, , , adCmdText
rst2.Open "SELECT * FROM Table1", cnn, , , adCmdText
rst.Sort = " ISBNnumber ASC"
rst.MoveFirst
rst2.MoveFirst
While Not rst.EOF
rst2!ISBNnumber = rst!ISBNnumber
rst2!Time = rst!Time
rst2!Name1 = rst!Name1
rst2!Name2 = rst!Name2
rst2!Author = rst!Author
rst2!Subject = rst! Subject
rst2.MoveNext
rst.MoveNext
Wend
rst2.UpdateBatch
rst.Close
rst2.Close
cnn.Close
End Sub
'---------------------------------
Rick Brandt - 03 Nov 2004 13:29 GMT
> Hello,
> I am looking for a good way to permanently sort a table in Access. The
> way i have below works but i was wondering if there is a better and
> faster way.
You're wasting your time. Tables in a relational database (by definition) have
no order. When you want the data in a particular order that is what queries are
for.

Signature
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Lyle Fairfield - 03 Nov 2004 13:52 GMT
> You're wasting your time. Tables in a relational database (by
> definition) have no order.
How do you think this applies to your statement?
**** from Books On Line ****
Organization of Data Pages
SQL Server 2000 tables use one of two methods to organize their data pages:
Clustered tables are tables that have a clustered index.
The data rows are stored in order based on the clustered index key. The
index is implemented as a B-tree index structure that supports fast
retrieval of the rows based on their clustered index key values. The pages
in each level of the index, including the data pages in the leaf level, are
linked in a doubly-linked list, but navigation from one level to another is
done using key values.
Heaps are tables that have no clustered index.
The data rows are not stored in any particular order, and there is no
particular order to the sequence of the data pages. The data pages are not
linked in a linked list.
Indexed views have the same storage structure as clustered tables.
**** end of quote ****
Rick Brandt - 03 Nov 2004 15:34 GMT
> > You're wasting your time. Tables in a relational database (by
> > definition) have no order.
[quoted text clipped - 20 lines]
> Indexed views have the same storage structure as clustered tables.
> **** end of quote ****
That speaks to physical storage which is not the same thing. BOL also
states the following...
**********************************
An explicit ORDER BY clause for a SELECT statement is required to ensure
any useful ordering of data. In addition, the exact results depend upon the
collation being used.
Expect different results as compared to earlier versions of SQL Server. Add
an explicit ORDER BY clause to all SELECT statements needing to produce
ordered rows.
**********************************

Signature
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
MacDermott - 03 Nov 2004 14:25 GMT
When you say you want your table permanently sorted, I think you mean that
you want it to always display in the same order - in this case, in ascending
order by ISBNnumber.
Some of the other posters have focussed on how the data is actually arranged
on the hard drive; I'm thinking that your focus is more on how it looks on
the screen.
You can see your data organized by ISBNumber whenever you open the table if
you'll define ISBNumber as the primary key.
However, I'd suggest that in the long run you'll be happier developing forms
to display your data.
Tables are really intended for storage, and don't offer as many options for
display and interaction as forms.
HTH
- Turtle
> Hello,
> I am looking for a good way to permanently sort a table in Access. The
[quoted text clipped - 39 lines]
> End Sub
> '---------------------------------