lwarren1968
Registered User.
- Local time
- Yesterday, 20:29
- Joined
- Jan 18, 2013
- Messages
- 77
At first I wanted to import several .txt files into access and then I was going to perform a Union Query to combined. All worked great accept for the fields are importing into one. With that being said, I've changed my mind!
I'd like to import several .txt files into access and have them load into one table. Can anyone help me fix what is missing below:
Sub ImportTextFiles()
Dim strPath As String
Dim strFile As String
Dim strTable As String
Dim strSpecification As String
Dim intImportType As AcTextTransferType
Dim blnHasFieldNames As Boolean
' Modify these values as needed
strTable = "G:\TRUE VALUE"
strSpecification = "True Value_Full_tbl"
blnHasFieldNames = False
intImportType = acImportDelim
' Let user select a folder
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "You didn't select a folder", vbExclamation
Exit Sub
End If
End With
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
' Loop through the text files
strFile = Dir(G:\TRUE VALUE"*.txt")
Do While strFile <> ""
' Import text file
DoCmd.TransferText _
TransferType:=intImportType, _
SpecificationName:=strSpecification, _
TableName:=strTable, _
FileName:=strPath & strFile, _
HasFieldNames:=blnHasFieldNames
strFile = Dir
Loop
End Sub
I'd like to import several .txt files into access and have them load into one table. Can anyone help me fix what is missing below:
Sub ImportTextFiles()
Dim strPath As String
Dim strFile As String
Dim strTable As String
Dim strSpecification As String
Dim intImportType As AcTextTransferType
Dim blnHasFieldNames As Boolean
' Modify these values as needed
strTable = "G:\TRUE VALUE"
strSpecification = "True Value_Full_tbl"
blnHasFieldNames = False
intImportType = acImportDelim
' Let user select a folder
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "You didn't select a folder", vbExclamation
Exit Sub
End If
End With
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
' Loop through the text files
strFile = Dir(G:\TRUE VALUE"*.txt")
Do While strFile <> ""
' Import text file
DoCmd.TransferText _
TransferType:=intImportType, _
SpecificationName:=strSpecification, _
TableName:=strTable, _
FileName:=strPath & strFile, _
HasFieldNames:=blnHasFieldNames
strFile = Dir
Loop
End Sub