The information in this article applies to:
- Microsoft Access 1.0, 1.1, 2.0, 7.0, 97
SYMPTOMS
Novice: Requires knowledge of the user interface on single-user computers.
When you use an index on a table without a primary index, the table
does not sort according to the order of the fields in the index.
CAUSE
Opening a table in Datasheet view is, internally, the same as opening a
recordset. If there is no primary index on the table, Microsoft Access uses
any field with a unique index to sort the recordset. If none or more than
one of the fields has a unique index, Microsoft Access chooses one at
random. The order of the indexes shown in the Index window has no bearing
on which index is used to sort the recordset.
RESOLUTION
To sort a recordset on a particular field, either make that field the
primary index for the table (by setting its PrimaryIndex property to Yes),
or use a query to sort the data.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Start Microsoft Access and open any database.
- Create a table with three fields. Make one of the fields an AutoNumber
field, and make the other two Text fields.
NOTE: In versions 1.x and 2.0, AutoNumber is called Counter.
- Do not specify a primary key for the table. Define an ascending
compound index on the two text fields. For example:
Index Name Field Name Sort Order
----------------------------------------
FieldText Field1 Ascending
Field2 Ascending
Set all index properties to No.
- Save the table, and then enter the following data in the table:
AutoNumber Field1 Field2
-----------------------
1 zzzz dddd
2 dddd yyyy
3 mmmm iiii
- Close the table, and then open it in Datasheet view. Note that it is
sorted as follows:
AutoNumber Field1 Field2
-----------------------
2 dddd yyyy
3 mmmm iiii
1 zzzz dddd
- Switch to Design view and add the AutoNumber field to the index:
Index Name Field Name Sort Order
----------------------------------------
AutoNumber Autonumber Ascending
FieldText Field1 Ascending
Field2 Ascending
Leave all the index properties set to No.
- Save and close the table, and then open it in Datasheet view. Note that
it is sorted as follows:
AutoNumber Field1 Field2
-----------------------
2 dddd yyyy
3 mmmm iiii
1 zzzz dddd
Instead of sorting first on the AutoNumber field, and then on Field1 and
Field2 as you might expect, the sorting remains unchanged.
- Set the AutNumber field's UniqueIndex property to Yes. The table is
sorted as:
AutoNumber Field1 Field2
-----------------------
1 zzzz dddd
2 dddd yyyy
3 mmmm iiii
Note that the data is sorted on the AutoNumber field.
REFERENCES
For more information about Indexes, search the Help Index for "indexes,
creating," or ask the Microsoft Access 97 Office Assistant.