Import text file into access

  • Thread starter Thread starter little_rascals
  • Start date Start date
L

little_rascals

Hi, i have to import a text file into access table.
However, there is a header at the top of the text file, which includes
the file name and date of file generated.
I need to extract the date only and input into one of the fields in the
table.

Can anyone kindly tell me how this can be done?!
Thanks!!! :D

Cheers,
little_rascals
 
G’day little_rascals…

It depends on the data format of the text file and your experience wit
recordsets.

Therefore this is just a generic reply for opening a text file and doe
not include any recordset manipulation.


Code
-------------------

Option Explicit
Option Compare Text


Private Sub AppendFromCSV()
Dim lngI As Long
Dim strBuffer As String
Dim intFileNumber As Integer

intFileNumber = FreeFile

Open "C:\xyz.csv" For Input As #intFileNumber

' Trash the first ten lines.
' Change 10 to 1 for just the Header.
For lngI = 1 To 10
Line Input #intFileNumber, strBuffer
Next lngI

Do Until EOF(intFileNumber)
Line Input #intFileNumber, strBuffer
'
' Do
' your
' thing.
'
Loop

Close #intFileNumber

End Sub

-------------------
If you wish to save the text file to a Table then please just ask.
I use DAO exclusively and would also need to know what version o
Access you are using.

Also, sample data from the text file and the Table structure would hel
answer your question.

Regards,
Chris
 
Back
Top