The AutoNumber data type is one major advantage of using Access. You can let the computer keep track of things like the next customer number to be assigned whenever a new record is created. If you read my article Primary Keys and Foreign Keys in Access, you know how important it is to have unique key fields.
Another advantage of Access is the ability of the program to import data from Excel and other delimited data files. That way, if you’ve been using another program to keep track of your customers and invoices it is relatively easy to move that data into Access. Since tables are the way that Access stores data, you can even create a table and import data on the fly using the Get External Data Wizard.
While it is perfectly okay to import data into a table that has a predefined AutoNumber field, you cannot convert an existing field into an AutoNumber field type. This becomes a problem sometimes because the command to import data and structure from Excel does not allow you to set a field type of AutoNumber. Bummer!
Converting a field of Number datatype to an AutoNumber datatype
The good news is that this problem is relatively easy to get around. For the purposes of this exercise, I am going to work with an imaginary table called tblOffices. I have imported it from Excel, but now I need the Primary Key column to be an AutoNumber datatype (right now it is a Number datatype of Long Integer).
- Right-click tblOffices in the Navigation Pane and choose Rename from the dropdown.
- Change the name of the table to tblOffices_TBD and press Enter. (TBD stands for To Be Deleted.)
- Right-click tblOffices_TBD in the Navigation Pane and choose Copy from the dropdown.
- Right-click in the Navigation Pane and choose Paste from the dropdown.
- Change the name to tblOffices.
- Click the Structure Only button beneath Paste Options.
- Click OK.
- Right-click tblOffices in the Navigation Pane and choose Design View from the dropdown.
- Change the Data Type for officeID to AutoNumber.
- Press Ctrl + S to Save.
- Press Ctrl + W to Close.
- Right-click tblOffices_TBD and choose Copy.
- Right-click tblOffices and choose Paste.
- Change the Table Name to tblOffices.
- Click the Append Data to Existing Table button beneath Paste Options.
- Click OK.
- Double-click tblOffices in the Navigation pane and confirm that the data is present.
- Right-click the tblOffices tab and choose Design View.
- Confirm that the Data Type for officeID is AutoNumber.
- Click tblOffices_TBD in the Navigation Pane.
- Press the Delete key on your keyboard.
- Click Yes in the warning dialog box.