Full Version: Removing Headers from file
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
phong919
Hello all,

I have the following file that i'm trying to create an import spec for it:

HDRIWSDDA17032007
111111111|16032007|4585.52
222222222|16032007|0.00
333333333|16032007|17860.88
TRLIWSDDA17032007

How can i remove the header and trailer for this file in an import spec? i just need the information in between the header and footer. Thank you.
Roger_Carlson
Unfortunately, you can't create an import spec to do that. I generally use low-level IO to import the text file. I have several examples on my website (see sig below) that illustrate this. "ImportLineInput.mdb" is one such.

Another thing you could do is run code to remove the header and footer and then import it through the wizard. Something like this:

CODE
Sub CleanFile(DirtyFile As String, CleanFile As String)



Dim MyString As String

Dim i As Integer

    

Open DirtyFile For Input As #1

Open CleanFile For Output As #2



Do While Not EOF(1)

    Line Input #1, MyString

    'Output the line Record

     If InStr(MyString, "|") > 0 Then

        Print #2, MyString

    End If



Loop

' Close text file.



MsgBox "Done!"



Close #1

Close #2



End Sub
And call it like this:

CODE
  Function RunCleanFiles()

Call CleanFile("C:\DirtyLineInput.txt", "C:\LineInput.txt")

End Function
This will read each line and only output the lines that have your delimiter ("|") in it.

Edited by: Roger_Carlson on Mon Mar 19 12:58:33 EDT 2007.

Edited by: Roger_Carlson on Mon Mar 19 12:59:21 EDT 2007.
khaos
Using an import spec I know of no way to ignore it. I have cases where I get records I don't need. In this case I let the bad record import and then I have an automated delete after import. This works as long as it is always recognizable. Yours look like this would work.

HTH
Ken
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.