Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Microsoft Office Access
Search
Search
 
Icon: Flag: (c) Microsoft
Get up to speed
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Fields that generate numbers automatically in Access
 
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

  1. Open the table in Design view.
  2. 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.
  3. In the Field Name column, type a name for the field.
  4. In the Data Type column, click the arrow and then click AutoNumber.
  5. 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.

Get Office 2007
Get Office 2007
advertisement