The easiest way to do this is as follows:
Open the source file
Code:
Dim strData As String
Dim IH As String
Open "C:\Test.Text2 For Input As #1
Open "C:\Header.Txt" For Output As #2
Open "C:\Detail.Txt" For Output As #3
Do Until EOF(1)
Line Input #1, strData
If Left(stData,2) = "IH" Then 'Header info
IH = Mid(strData,3,8)
Print #2, Mid(strData,4) ' Write header details to the header txt file
Else
Print #3, IH & "|" & Mid(strData,4) ' Write detail to the details txt file with the IH prefixed to the detail line
End If
Loop
Close #1
Close #2
Close #3
So what we have ended up with is the original text file
plus 2 new files
Header.Txt
AF374556|2006-06-05|Bob Smith|3 Berk St||Boston|MA| 02199
Detail.Txt
AF374556|4056|4|55.50|Floor Lamp|Ground|Test Comment
AF374556|BC456|1|17.75|Hall Lamp|Ground|Test Comment 2
Now we can perform two imports first into the header table, second into the detail table. The IH and ID prefixes have been removed from the import as they are not needed anymore.
David