Pages

Thursday, December 29, 2011

Import Csv File In Table

If you want to import the csv file as table in access database.

Here is the code-

Sub import_csv_file_to_access_table()
Dim tbl As DAO.TableDef
Dim found As Boolean
Dim tbl_name_to_check As String
tbl_name_to_check = "rep_name"
found = False
' check if table exists or not
For Each tbl In CurrentDb.TableDefs
If tbl.Name = tbl_name_to_check Then
found = True
Exit For
End If
Next
If found = True Then
MsgBox "Table Already Exists ", vbInformation
Else
'import the csv file to access table
DoCmd.TransferText acImportDelim, "", tbl_name_to_check, "C:\Users\ashishkoul\Desktop\learn\rep_name_a.csv", True
MsgBox "Records Imported Successfully", vbInformation
End If
End Sub

Download Access Database

No comments:

Post a Comment