Others

How to Fix Access Import Errors Caused by Blank Primary-Key Values

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 868 views

Question details

The user is experiencing an error when importing an Excel spreadsheet into a database because the designated primary key field contains blank values.

Fixing Access Import Errors Caused by Blank Primary-Key Values
Product
Microsoft Access / Excel
Device & OS
not provided
Scenario
Importing an Excel spreadsheet into Access where the CODE column is set as the primary key, but some records in the spreadsheet lack a value in this column.
Observed behavior
An error message appears when closing the imported table, indicating that the primary-key field contains invalid null (blank) values.
Before you start

Review your original Excel spreadsheet to identify the column intended to serve as your unique identifier, and check if any cells in that column are empty.

Solution 1Recommended

Use an AutoNumber Field as a Surrogate Primary Key

Allow Access to automatically generate a unique primary key during the import process so your original column can safely contain blank values.

A fundamental rule of relational databases is that a primary key must be entirely unique for every record and cannot contain null (blank) values. If your original CODE field has missing data, it cannot function as the primary key.

Instead of forcing the CODE column to act as the primary key, you can instruct Access to create a new AutoNumber column specifically to serve as the primary key. Your CODE column will then be imported as a standard text field.

1
Start the import wizard

Open your Access database, navigate to the External Data tab, select 'New Data Source', and choose 'From File' followed by 'Excel'.

2
Select the spreadsheet

Browse for your Excel file, choose to import the source data into a new table, and click OK to proceed through the initial wizard prompts.

3
Set the primary key to AutoNumber

When you reach the primary key configuration step in the wizard, select the 'Let Access add primary key' option. Access will add a new ID column with an AutoNumber data type.

4
Complete the import

Click Next, name your new table, and click Finish. The table will close without error, and your original CODE field will retain its combined text and numbers alongside the blank cells.

Use an AutoNumber Field as a Surrogate Primary Key
Data Integrity Maintained: Combining text and numbers in a regular field is perfectly acceptable. The AutoNumber field ensures database integrity without requiring you to alter your original spreadsheet data.
Free Microsoft Office alternative

Prepare Your Spreadsheets Seamlessly with WPS Office

While Microsoft Access is used for database management, data preparation often starts in a spreadsheet. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Excel. Easily clean your data, fix blank cells, and ensure perfect compatibility with Microsoft Office formats before importing your records.

  1. 1. Download and install: Visit the official WPS website and install the free WPS Office suite on your computer.
  2. 2. Open your data file: Launch WPS Spreadsheet and open your existing .xlsx or .csv files seamlessly without losing formatting.
  3. 3. Clean and format: Utilize built-in filtering tools to quickly spot and resolve blank primary key fields before importing them into your database.
Completely free and lightweight Office suitePerfect format compatibility with Microsoft Excel (.xlsx, .xls, .csv)Familiar user interface with zero learning curve for seamless migrationPowerful data filtering and cleaning tools to prepare imports
microsoft office alternative - wps office

Frequently Asked Questions

Can a primary key contain both letters and numbers?

Yes, a primary key can safely combine text and numbers (alphanumeric). The only strict database requirements are that every value in the field must be completely unique and no value can be blank (null).

What does a 'null value in primary-key' error mean?

This error means that the column you selected to be the primary identifier for your database table has at least one empty cell. Relational databases require every single row to have a specific, non-empty identifier to track relationships accurately.

Can I change the primary key after importing the Excel file?

Yes. If you import the data without assigning a primary key, you can later open the table in Access Design View, clean up any blank records, and then manually set a specific field as the primary key.

What is an AutoNumber surrogate key?

An AutoNumber surrogate key is a system-generated column (usually an ID) that automatically assigns a sequential number to every new record. It acts as the unique identifier behind the scenes, allowing your actual business data columns to remain flexible.