Pages

Showing posts with label Import Text File as Table in Access Database. Show all posts
Showing posts with label Import Text File as Table in Access Database. Show all posts

Thursday, December 29, 2011

Import Text File as Table in Access Database

If you want to import the text file in access database.

Here is the code-

Sub import_text_file_into_access()
Dim tbl As DAO.TableDef
Dim found As Boolean
Dim tbl_name_to_check As String
tbl_name_to_check = "rep_name_a"
found = False
' check if table exists
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
' the below will import the text which is delimited with comma and text qualifier as double quotes
' use false if the text file is not having headers
DoCmd.TransferText acImportDelim, , tbl_name_to_check, "C:\Users\ashishkoul\Desktop\learn\rep_name_a.txt", False
MsgBox "Records Imported Successfully", vbInformation
End If
End Sub


Download Access Database