|
Question : How do I import a .csv file using VBA?
|
|
Hi Experts,
How do I import a .csv file using VBA?
Thanks
|
|
Answer : How do I import a .csv file using VBA?
|
|
Hi indyng,
You can use the DoCmd.TransferText command to accomplish your task easily.
DoCmd.TransferText acImportDelim, "SpecificationName", "TableName", "Filename", True{False}
The Specification Name is useful for creating certain rules about the data
the last parameter True is if file has headings or not
specifications is optional, first try without DoCmd.TransferText acImportDelim, , "TableName", "Filename", True
Try this code ------------------------------------------------------------------------------ Function MyCSVImport() On Error GoTo MyCSVImport_Err
DoCmd.TransferText acImportDelim, "YourImportSpecName","YourTableName", "YourCSVFileName.csv", True ' if first line of csv file headings
'DoCmd.TransferText acImportDelim, "YourImportSpecName","YourTableName", "YourCSVFileName.csv", False ' if first line of csv file dost not have headings.
MyCSVImport_Exit: Exit Function
MyCSVImport_Err: MsgBox Err.Description Resume MyCSVImport_Exit
End Function --------------------------------------------------------------------------------- Hope you like it.
Regards, SriRamIyer
|
|
|
|