Remove 2 lines from text file before transfertext

  • Thread starter Thread starter scrawf
  • Start date Start date
S

scrawf

Hi all,

I'm trying to import a text file, but before I do I need to remove the
first two lines, which ruin the headings for the table. I've got a
routine that asks the user where the file is, so before I do the
transfertext I need to just open up the file and rip out the first two
lines of junk then import. Is there an easy way to do this?

Cheers,

Scott
 
Hi Scott,

Try a function something like this. It accepts two string parameters, one
for the full path of the source file and one for the full path of the newly
created text file. You can test it from the Immediate Window (Ctrl G) by
entering the following:

StripFirstTwolines "C:\Temp\Source.txt", "C:\Temp\Cleaned.txt"

Function StripFirstTwoLines(strInputFile As String, _
strOutputFile As String) As Boolean
On Error GoTo ProcError


Dim strRecord As String

' Open strInputFile for reading
Open strInputFile For Input As #1

' Create the output filename by opening it.
Open strOutputFile For Output As #2

Line Input #1, strRecord
Line Input #1, strRecord

Do While (Not EOF(1))
Line Input #1, strRecord
Print #2, strRecord
Loop

StripFirstTwoLines = True

ExitProc:
On Error Resume Next
Close 'Close the files
DoEvents
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure StripFirstTwoLines..."
StripFirstTwoLines = False
Resume ExitProc

End Function



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top