Data Import & Export

Automatically Import a Daily CSV File into Microsoft Access

Elise WilliamsElise Williams Nov 27, 2026 868 views

Question details

Import a daily CSV export into an Access table automatically when the database opens, replacing the previous records without linking to the CSV.

Automatically Import a Daily CSV File into Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
A kiosk opens an Access database that needs current data from a daily CSV export.
Observed behavior
The database should import the latest CSV into a standard table and replace the old records at startup.
Before you start

Confirm that the daily CSV has a consistent path, column layout, and header row, and that the kiosk account can read it. Make sure the database is trusted so Access can run startup VBA.

Solution 1Recommended

Import the CSV at startup with VBA and a staging table

Use a saved import specification and a startup form to load the CSV before replacing the permanent table’s records.

TransferText imports data but does not automatically replace records in an existing table. This approach imports into a staging table first, then replaces the permanent table’s data in a transaction.

The example expects matching ID and ItemName fields in both tables and a CSV with column headers. Adapt the field names, path, and specification to your data.

1
Save an import specification

In Access, select External Data > New Data Source > From File > Text File and choose the CSV. In the import wizard, select Advanced, configure the fields, and use Save As to save the specification as DailyCSVSpec. Complete the import into a new table named DailyImportStaging.

2
Prepare the destination table

In the Navigation Pane, create or identify the permanent table, named DailyData in this example. Ensure its ID and ItemName fields accept the corresponding staging-table values. Check relationships and constraints before allowing its existing records to be deleted.

3
Add the import function

Press Alt+F11, select Insert > Module, and add the following function. Change the CSV path and SQL field names to match your database: Public Function RefreshDailyCSV() As Boolean Dim db As DAO.Database Dim ws As DAO.Workspace Dim inTransaction As Boolean Dim csvPath As String On Error GoTo ImportError csvPath = "C:\Data\daily.csv" If Dir(csvPath) = "" Then Err.Raise vbObjectError + 1000, , "CSV file not found: " & csvPath Set db = CurrentDb Set ws = DBEngine.Workspaces(0) db.Execute "DELETE FROM DailyImportStaging", dbFailOnError DoCmd.TransferText acImportDelim, "DailyCSVSpec", "DailyImportStaging", csvPath, True ws.BeginTrans inTransaction = True db.Execute "DELETE FROM DailyData", dbFailOnError db.Execute "INSERT INTO DailyData (ID, ItemName) SELECT ID, ItemName FROM DailyImportStaging", dbFailOnError ws.CommitTrans inTransaction = False RefreshDailyCSV = True Exit Function ImportError: If inTransaction Then ws.Rollback MsgBox "Daily CSV import failed: " & Err.Description, vbExclamation RefreshDailyCSV = False End Function

4
Run the function when the form opens

Open the startup form in Design View. In its Property Sheet, select the Event tab, set On Open to Event Procedure, and click the builder button. Add `If Not RefreshDailyCSV() Then Cancel = True` inside the Form_Open procedure. Under File > Options > Current Database, select the form as the Display Form, then reopen the database to test.

5
Schedule startup if needed

If the database must open at a fixed time, create a task in Windows Task Scheduler that launches the Access database under an account with access to both the database and CSV.

Import the CSV at startup with VBA and a staging table
Check the CSV before deployment: The saved import specification is stored in the Access database, not as a separate file. Test missing, malformed, and empty CSV files; the example treats a successfully imported empty file as an empty replacement dataset.
Free Microsoft Office alternative

Work with CSV exports in WPS Spreadsheet

WPS Office is a free, lightweight alternative for viewing and editing CSV exports and familiar Microsoft Office files. Its familiar interface and format compatibility make it easy to move everyday spreadsheet work, although it does not automate or replace Microsoft Access database imports.

Open and review daily CSV exports in WPS SpreadsheetCompatible with Microsoft Excel formats such as XLSX and XLSFamiliar spreadsheet interface for everyday editingFree and lightweight for routine office work
microsoft office alternative - wps office

Frequently Asked Questions

Can TransferText overwrite an existing Access table?

TransferText does not automatically replace existing table records. Import into a staging table, then use delete and append queries to replace the destination data.

Where is the saved CSV import specification?

An Access import specification is stored in the database. Open the text import wizard, select Advanced, and use Save As to create a named specification that TransferText can reference.

How can I run the import without a startup form?

Create an AutoExec macro and use its RunCode action to call a public VBA function in a standard module. Access runs the AutoExec macro when the database opens, subject to its security settings.

What happens if the daily CSV is missing?

The example checks the path with Dir before clearing the staging table. If the file is missing, it reports an error and leaves the permanent table unchanged.