Index or primary key cannot contain a Null value. (Error 3058)

Possible causes:

  • You tried to add a new record but did not enter a value in the field that contains the primary key.
  • You tried to add a Null value to a primary key field.
  • You executed a query that tried to put a Null value in a primary key field.

What Is a Primary Key?

A primary key is a field or set of fields in your table that provide Microsoft Office Access 2007 with a unique identifier for every row. In a relational database, such as an Office Access 2007 database, you divide your information into separate, subject-based tables. You then use table relationships and primary keys to tell Access how to bring the information back together again. Access uses primary key fields to quickly associate data from multiple tables and combine that data in a meaningful way.

Often, a unique identification number, such as an ID number or a serial number or code, serves as a primary key in a table. For example, you might have a Customers table where each customer has a unique customer ID number. The customer ID field is the primary key.

An example of a poor choice for a primary key would be a name or address. Both contain information that might change over time.

Access ensures that every record has a value in the primary key field, and that the value is always unique.

What Is a Null?

A Null is a value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Microsoft Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, cannot contain Null.

Solution

To solve this problem, you must enter a value in the primary key field before moving to another record.


See Also
  • Create or remove a primary key


Community Additions

Show:
© 2014 Microsoft