Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the following steps to import a CSV file into a new table in MS Access VBA while ensuring that the column names of the table are enforced:

  1. Create a Schema.ini file: A Schema.ini file is a text file that contains information about the format and layout of the CSV file. It includes details like the data type and width of each column. You can use a Schema.ini file to ensure that the column names are enforced during the import process.

  2. Create a new table in MS Access: In the MS Access database, create a new table with the same structure as the CSV file. Ensure that the column names in the table match the column names in the CSV file.

  3. Use SQL to execute the import: In VBA, use SQL to execute the import process. Here is an example:

Dim sql As String

sql = "INSERT INTO MyNewTable SELECT * FROM [Text;FMT=Delimited;HDR=Yes;Database=C:\MyFolder].[MyCSVFile.csv];"

DoCmd.RunSQL sql

This will insert all the data from the CSV file into the new table. The [Text;FMT=Delimited;HDR=Yes;Database=C:\MyFolder].[MyCSVFile.csv] part of the SQL statement tells MS Access to treat the CSV file as a delimited file with a header row.

  1. Run the import process: Run the SQL statement to execute the import process. The data from the CSV file will be added to the new table in MS Access, with the column names enforced.