Help with two *.txt files.

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?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You will have to create an import specification and save it. You can then use it in a VBA code. To create an import specification, begin to import a txt file manually into Access. When you get to the screen that is defining the fields, click on Advanced. Determine the type of field for each you will import and check appropriately for those that you will not import.

Since you did not indicate which version of Access you are using, I have included a link for AC2003 that will demo this procedure.

Creating an Import Specification in Access 2003 - Access Programmers

Here is an alternative

ACC: How to Create a Schema.ini File Programmatically
 
Last edited:
Upvote 0
Makes no difference. You will still need to create an import specification. You do it the same way in 2003 and 2007 and 2010. It is the same. Only the interface icons are different. Instead of File Import in 2003, on the ribbon, you will use External Data-->Import and the same interface will then open.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top