How to Import CSV Files into Access Without Duplicates
Question details
The user wants to prevent importing duplicate records when running repeated VBA scripts to import CSV files into Microsoft Access.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Running repeated VBA import operations on a source folder containing CSV files.
- Observed behavior
- Previously processed CSV files are imported again, creating duplicate records in the destination Access database.
Before modifying your VBA code or database structure, ensure you create a backup copy of your Access database to prevent accidental data loss during testing.
Move Processed CSV Files to a Subfolder
Use VBA to automatically move files to a different folder after a successful import so they are not processed again.
The most straightforward way to prevent duplicate file imports is to physically separate processed files from unprocessed ones. By relocating a CSV file the moment it finishes importing, your source folder will only ever contain new data.
Navigate to the directory where your source CSV files are stored and create a new folder named 'Imported'.
Open your Access database and press ALT + F11 to launch the VBA editor.
Locate your CSV import script and insert the 'FileSystemObject.MoveFile' method or the standard 'Name [OldPath] As [NewPath]' statement at the very end of your import loop.
Configure the destination path in your code to point to the 'Imported' subfolder, ensuring the file is relocated immediately after processing completes.
Enforce a Unique Index on the Destination Table
Prevent duplicates at the database level by setting a unique index on a reliable identifier in your Access table.
Use a Tracking Table for Processed Filenames
Maintain a log of imported filenames within the database and check against it before processing a file.
Looking for a Lightweight Office Suite? Try WPS Office
While Microsoft Access is a tool for complex relational databases, many users rely on Office tools for spreadsheet data management. If you are handling large CSV files and want a fast, free, and highly compatible alternative to Microsoft Office for your daily tasks, WPS Office is an excellent choice. It provides powerful data processing capabilities without the steep learning curve of VBA.
- 1. Download and Install: Get the free WPS Office suite from the official website and install it on your device.
- 2. Open CSV Files: Launch WPS Spreadsheet and drag-and-drop your CSV files to view and edit them instantly.
- 3. Remove Duplicates Easily: Highlight your data, navigate to the Data tab, and click 'Remove Duplicates' to clean your dataset visually without coding.

Frequently Asked Questions
Can I prevent duplicate CSV imports using standard Access macros instead of VBA?
Standard Access macros have limited file system operations. To dynamically check file names, move files to new directories, or log files during an import loop, you must use VBA (Visual Basic for Applications).
What happens if a CSV file fails to import halfway through?
If an error occurs, proper VBA error handling should prevent the file from moving to the 'Imported' folder or being logged in the tracking table. This allows you to fix the underlying data issue and re-run the process safely.
How do I handle duplicate rows inside the same CSV file?
Setting a 'Unique Index' (No Duplicates) on your Access destination table is the best way to handle internal file duplicates. Access will import the first instance of the record and reject the subsequent duplicates found within the same CSV file.




