l KAUTION l
Board Regular
- Joined
- Nov 3, 2005
- Messages
- 90
I have a folder of txt files that I would like to import. I would like each file to have its own table. I need to delimit the files using a specification named Delimiter. I was playing around with some code but have been unsuccessful so far. The code imports everything in the folder into one table and does not delimit the files. Any help would be much appreciated. Thanks in advance.
The code below is what I was playing with...
Private Sub Command0_Click()
Dim Counter As Integer
With Application.FileSearch
.NewSearch
.LookIn = "G:\PLSHARED\Conversion Team\~Temp" 'change this to your actual directory
.SearchSubFolders = False 'set to True if you want to search subfolders too
.FileName = "*.txt" 'get all files in the directory
If .Execute() > 0 Then 'files found
For Counter = 1 To .FoundFiles.Count 'loop through files
.FileName = .FoundFiles(Counter) 'set / get the file name
'Change the "ImportFile" part in the line below if you are using a different table name
DoCmd.TransferText acImportDelim, "Delimiter", "Import", .FileName, False 'import
DoEvents 'don't take over all of the PC resources
Next Counter
MsgBox "Import complete.", vbInformation, "Done"
Else 'files not found
MsgBox "There were no files found.", vbCritical, "Error"
End If
End With
End Sub
The code below is what I was playing with...
Private Sub Command0_Click()
Dim Counter As Integer
With Application.FileSearch
.NewSearch
.LookIn = "G:\PLSHARED\Conversion Team\~Temp" 'change this to your actual directory
.SearchSubFolders = False 'set to True if you want to search subfolders too
.FileName = "*.txt" 'get all files in the directory
If .Execute() > 0 Then 'files found
For Counter = 1 To .FoundFiles.Count 'loop through files
.FileName = .FoundFiles(Counter) 'set / get the file name
'Change the "ImportFile" part in the line below if you are using a different table name
DoCmd.TransferText acImportDelim, "Delimiter", "Import", .FileName, False 'import
DoEvents 'don't take over all of the PC resources
Next Counter
MsgBox "Import complete.", vbInformation, "Done"
Else 'files not found
MsgBox "There were no files found.", vbCritical, "Error"
End If
End With
End Sub