0

first of all I'd like to say thanks. Although I'm still pretty new to it, I've learned nearly everything I know about Access from this site. This is one of the most helpful forums I've ever used.

I'm having a problem importing data to my Access database from my Excel spreadsheet. I keep getting a key violation saying a particular field (column) in each row was deleted. I have two tables on my database and two coinciding sheets on my spreadsheet. Both sheets have this particular field. Sheet1 is importing fine, but Access won't import anything from that field on sheet2. All the properties for this field are the same and the data preview during import verifies that the data is coming from both sheets in the same form.

From this source: http://www.utteraccess.com/forum/Key-Violations-Append-Q-t1918322.html Key violations occur for 3 reasons:

1) when the record you are attempting to add to the table adds a duplicate value where the field does not allow duplicates - This can't be it because every value in the field is unique and the field is set to allow duplicate values. And my primary key is the Access-generated replication ID.

2) when the record has a field value that is null and the field in the table is a required field - the field on sheet1 is adding null values, and not all the values on sheet2 that won't add are null value. and the fields are set to accept null values.

3) Where a value is added that is not in a related table and referential integrity is set on the link between the tables - I have no relationships set in my database yet.

I have done this import successfully before a few times and I've only made minor changes since then, the majority of which on the Excel file. Thanks for any replies, and thanks very much for any explanations.

4

1 回答 1

0

我找到了一个很好的替代解决方案来解决这个问题。我没有直接将数据导入我在 Access 中构建的表以匹配我的 Excel 工作表,而是通过让 Access 创建一个新表来导入工作表。此表会自动格式化以匹配我从中导入的 excel 文件。

于 2013-07-03T20:40:01.253 回答