Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use VBA to import a CSV file into Microsoft Access using the TransferText method. Here is an example code:

Sub ImportCSV()

Dim dbName As String
Dim csvPath As String

dbName = "C:\Users\USERNAME\Desktop\Database.accdb"
csvPath = "C:\Users\USERNAME\Desktop\file.csv"

DoCmd.TransferText acImportDelim, , "TableName", csvPath, True

End Sub

In this code, replace "USERNAME" with your own Windows username, and "Database.accdb" with the name of your Access database file.

Replace "TableName" with the name of the table in Access where you want to import the CSV file.

Replace "file.csv" with the name and path of your CSV file.

The True parameter in the TransferText method indicates that the first row in the CSV file contains column headers.

To run the code, open the Microsoft Visual Basic Editor in Access by pressing Alt + F11, then copy and paste the code into a new module. Save the module, and then run the macro by clicking the "Run" button.