| Applies to |
| Microsoft Access 2000 and 97 |
In an Access database, you can create a field that automatically generates a unique number when you enter a new record in a table.
To create an AutoNumber field
- Open the table in Design view.
- To insert the field in the table, right-click in the row below where you want to add the field, and then click Insert Rows on the shortcut menu.
- In the Field Name column, type a name for the field.
- In the Data Type column, click the arrow and then click AutoNumber.
- If you want the values in the field to be random instead of sequential, click the NewValues box
in the bottom part of the window, and change the setting from Increment to Random.
Tips
- Because the value in an AutoNumber field is unique for each record in a table, an AutoNumber field is a suitable choice for a table's primary key.
- You can't change the value in an AutoNumber field.
- If you delete records at the end of the table that contains an incrementing AutoNumber field, the values that existed in the AutoNumber field of the deleted records will be reused after you compact the database. For example, suppose the values in the AutoNumber field of a table are 1, 2, 3, and 4. If you delete record 4, compact the database, and then add a new record, the value of the AutoNumber field in that record will be 4.
- If you delete records that are not at the end of the table, the values that existed in the AutoNumber field of the deleted records are not reused. For example, if the values in the AutoNumber field of your table are 1, 2, 3, and 4, and if you delete record 2, the value of the AutoNumber field in the deleted record is not reused - even after you have compacted the database.
For more information about AutoNumber fields, type incrementing AutoNumber fields in the Office Assistant or on the Answer Wizard tab in the Help window, and then click Search.
For more information about compacting an Access database, type compact a database in the Office Assistant or on the Answer Wizard tab in the Help window, and then click Search.