vba code to import ile

griffins69

griffins69
Local time
Today, 09:52
Joined
Apr 15, 2010
Messages
18
I've used the code below to import a text file(with header record) into Access, but I don't know how to take the header of my file when I bring the file. It's a small part but I'm not sure how to get it done.

Thanks


Dim F As Long, sLine As String, A(0 To 4) As String
Dim db As Database, rs As Recordset
F = FreeFile
Open "c:\temp\test.txt" For Input As F
' uncomment following line if you want to skip field headings
' Line Input #F, sLine
Set db = CurrentDb
On Error Resume Next
' db.Execute "DROP TABLE TestImport"
On Error GoTo 0
' db.Execute "CREATE TABLE TestImport (ID LONG, [Desc] TEXT (50), " _
' & "Qty LONG, Cost CURRENCY, OrdDate DATETIME)"
Set rs = db.OpenRecordset("TestImport", dbOpenTable)
Do While Not EOF(F)
Line Input #F, sLine
ParseToArray sLine, A()
rs.AddNew
rs(0) = Val(A(0))
rs(1) = A(1)
rs(2) = Val(A(2))
rs(3) = Val(A(3))
rs(4) = CDate(A(4))
rs.Update
Loop
rs.Close
db.Close
Close #F
End Sub
Sub ParseToArray(sLine As String, A() As String)
Dim P As Long, LastPos As Long, i As Long
P = InStr(sLine, "|")
Do While P
A(i) = Mid$(sLine, LastPos + 1, P - LastPos - 1)
LastPos = P
i = i + 1
P = InStr(LastPos + 1, sLine, "|", vbBinaryCompare)
Loop
A(i) = Mid$(sLine, LastPos + 1)
End Sub
 
Did you not read the code that is here? It actually TELLS you how to remove the header.

Dim F As Long, sLine As String, A(0 To 4) As String
Dim db As Database, rs As Recordset
F = FreeFile
Open "c:\temp\test.txt" For Input As F
' uncomment following line if you want to skip field headings
' Line Input #F, sLine
 
Thanks
I've been looking at so much code I simply blew it.
 

Users who are viewing this thread

Back
Top Bottom