krismcmillan
New Member
- Joined
- Aug 22, 2014
- Messages
- 17
Hi
I'm trying to import two *.txt files into one Access table. I have managed to find some coding, which opens a folder (containing the two .txt files).
Option Compare Database
Sub cmdImport_Click()
Dim strPath As String
Dim strFile As String
Dim strTable As String
Dim strSpecification As String
Dim intImportType As AcTextTransferType
Dim blnHasFieldNames As Boolean
strTable = "tblASN"
strSpecification = ".txt"
blnHasFieldNames = False
intImportType = acImportDelim
' Let user select a folder
With Application.FileDialog(4)
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
DoCmd.OpenForm "frmMessage"
Forms!frmMessage.Repaint
' Loop through the text files
strFile = Dir(strPath & "*.txt")
Do While strFile <> ""
' Import text file
DoCmd.TransferText _
TransferType:=intImportType, _
SpecificationName:=strSpecification, _
TableName:=strTable, _
FileName:=strPath & strFile, _
HasFieldNames:=blnHasFieldNames
strFile = Dir
Loop
DoCmd.Close acForm, "frmMessage"
End Sub
But I get an Run-Time error 3625,The text file specification '.txt' does not exist. You can import, export, or link using the specification.
I'm not sure if I need to specify the correct file name or not.
Also is there anywhere on the internet, that has a list of codes and help to newbies - like myself?
I'm trying to import two *.txt files into one Access table. I have managed to find some coding, which opens a folder (containing the two .txt files).
Option Compare Database
Sub cmdImport_Click()
Dim strPath As String
Dim strFile As String
Dim strTable As String
Dim strSpecification As String
Dim intImportType As AcTextTransferType
Dim blnHasFieldNames As Boolean
strTable = "tblASN"
strSpecification = ".txt"
blnHasFieldNames = False
intImportType = acImportDelim
' Let user select a folder
With Application.FileDialog(4)
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
DoCmd.OpenForm "frmMessage"
Forms!frmMessage.Repaint
' Loop through the text files
strFile = Dir(strPath & "*.txt")
Do While strFile <> ""
' Import text file
DoCmd.TransferText _
TransferType:=intImportType, _
SpecificationName:=strSpecification, _
TableName:=strTable, _
FileName:=strPath & strFile, _
HasFieldNames:=blnHasFieldNames
strFile = Dir
Loop
DoCmd.Close acForm, "frmMessage"
End Sub
But I get an Run-Time error 3625,The text file specification '.txt' does not exist. You can import, export, or link using the specification.
I'm not sure if I need to specify the correct file name or not.
Also is there anywhere on the internet, that has a list of codes and help to newbies - like myself?