Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I want to link multiple .txt files of different columns in access via VBA. I have made link spec named as " GCELL_Specification" and using the following code.
The problem is Access is making same headers in all linked files as the headers of Spec. Its messing all the linked files. Can anyone tell me how to use a single spec in linking multiple tables of different headers.
Or can anyone tell me how to link without spec so that access takes datatype by default for each table. I tried this but access giving the error of 3011.
The code that i am using is :

VB
Private Sub btn_dir_Click()
Dim objFSO As FileSystemObject
Dim objFile As File
Dim ObjDirRoot As Folder

Dim PageName As String

Set objFSO = New FileSystemObject
    Set ObjDirRoot = objFSO.GetFolder("D:\Compiled DB\North")
For Each objFile In ObjDirRoot.Files
PageName = objFile.Name
DoCmd.TransferText acLinkDelim,"GCELL_Specification" , PageName, objFile.Name, True 
    Next

End Sub

Thanks in advanced.
Posted
Updated 13-Mar-14 11:16am
v2
Comments
Farah Siraj 13-Mar-14 7:49am    
Sorry by mistake, i posted objFile.Name instead of objFile.Path
My Question is the same as above.

1 solution

Have a look here: DoCmd.TransferText Method (Access)[^]

SpecificationName:
(...) For delimited text files and Microsoft Word mail merge data files, you can leave this argument blank to select the default import/export specifications.
 
Share this answer
 
Comments
Farah Siraj 14-Mar-14 4:18am    
Thanks, I have linked/imported tables as i desired but still the problem is whenever i import tables again and again, Access create create another tables with the same succeeding with 1,11 and so on while remaining old imported tables. I tried to delete records from old imported tables but no effect in creation of new table every time i click import.
Is it possible to replace the old imported table by the new table with the same name???

Thanks in advanced.
Maciej Los 14-Mar-14 15:33pm    
Before you start importing data, you should delete existing table by using DoCmd.DeleteObject Method (Access)[^].
DoCmd.DeleteObject acTable, "TableName"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900