Importing Excel Data into Access Using Index - How to Prevent Popup Message

十年热恋 提交于 2019-12-11 04:25:33

问题


I am trying to use an Index to import monthly data from Excel into a Table (by Appending new records to the Table).

I have created a unique index in the Table being posted to to prevent the import of duplicate records.

However when I click import (and assuming the records already exist) it still gives the user the option to import the same records again by clicking yes to the message below:

How would I get the macro to not run if the entries already exist and also not give the user the above message option?

I have tried suppressing messages temporarily using a bit of code as referred to below, but that just processes the import anyway and re-adds the entries to the table again.

Thanks


回答1:


Excel imports often have issues (even if you haven't found any in this particular file), expecially if the Excel file is created or edited by humans. My suggestion would be to import the file into a temporary table consisting of all text fields (F1, F2, etc) and an identity field. Using all text fields, all data should import without any conversion problems. Don't use the first row as column heads. Import it as the first row of data. That way you can easily check for correct column headings. If correct, just delete that row.

Then validate and scrub the data using queries and/or code against the temporary table to identify any data that does not meet the requirements of your permanent tables. E.G. Select * From WHERE Not IsNumeric(F3).

Then remove any leading or trailing spaces, double spaces, etc. and whatever other cleanup you might like to do.

Then use a query with an outer join (on your PK fields) to append rows from the temp table, that are not already in the permanent table, to the permanent table.



来源:https://stackoverflow.com/questions/42688999/importing-excel-data-into-access-using-index-how-to-prevent-popup-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!