Ask Your Question
2

How can I use VBA to bring a csv file into MSAccess?

asked 2022-02-02 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-09-08 20:00:00 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-02 11:00:00 +0000

Seen: 12 times

Last updated: Sep 08 '21