How can be done? Can be done?

J

Jay

I need a function to loop through and import data into a table from a text
file
which is laid out as follows:
=============
[Contacts.txt]
ColNameHeader=True
Format=FixedLength
MaxScanRows=0
CharacterSet=OEM
Col1="Time" Char Width 7
Col2="FV_Cor" Char Width 7
Col3="FV_Nom" char Width 7
Col4="ADD" char Width 4
Col5="ADD_Ca" char Width 6
Col6="DI" Char Width 3
Col7="E" char Width 2
Col8="Lot_Number" char Width 12
Col9="Mar" char Width 4
Col10="Tin" char Width 4
Col11="SKU_Code" char Width 11
Col12="D_A_B" Char Width 6
Col13="Pad_X" char Width 6
Col14="Pad_Y" char Width 6
Col15="Pad_Z" char Width 6
Col16="MI_Tr" char Width 6
Col17="Check" char Width 6
Col18="Check_V" char Width 3
Col19="Quali" char Width 6
Col20="Quali_V" char Width 2
Col21="GR" char Width 3
Col22="Radius_CC" char Width 9
Col23="Index" char Width 7
Col24="CenTh" char width 6
Col25="Clic" char width 5
Col26="Bnom" char width 5
Col27="Pa" char width 3
Col28="Dpt_Cal" char width 8
Col29="ProX" char width 5
Col30="ProY" char width 5
Col31="GriX" char width 5
Col32="GriY" char width 5
Col33="CliX" char width 5
Col34="CliY" char width 5
Col35="ErrPro" char width 6
Col36="Suivi" char width 6
Col37="T_Tot" char width 6
Col38="T_Man" char width 6
Col39="Resea" char width 6
Col40="T_L" char width 4
Col41="T_P" char width 4
Col42="T_O" char width 4
Col43="TPC" char width 4
Col44="TQC" char width 4
Col45="T_" char width 4
Col46="TXY" char width 4
Col47="TRO" char width 4
Col48="_" char width 4
=============

If you can assist, it will be appreciated! This is an Schema.ini structure,
but, I'd like to change it into a looping function (placing data columns in
their respective places in the target table) since there may be multiple
files under various names that will need to be imported.
 
J

John Nurick

Hi Jay,

I suspect it would be much simpler to write code to create a new
schema.ini with the necessary file name in the [section header].

But if you want to do it your way, you could do something like this;

-Open a recordset on the table
-Open the text file

Do until end of file

-Add a new record and read a line from the file, e.g.
rstR.AddNew
Line Input #1, strLine

-Parse the line and populate the new record with a succession of calls
to Mid(), e.g.
With rstR
.Fields("strTime") = Mid(strLine, 1, 7)
.Fields("strFV_Cor") = Mid(strLine, 8, 7)
...
.Fields("_") = Mid(strLine, blah blah)
.Update
End With

Loop





I need a function to loop through and import data into a table from a text
file
which is laid out as follows:
=============
[Contacts.txt]
ColNameHeader=True
Format=FixedLength
MaxScanRows=0
CharacterSet=OEM
Col1="Time" Char Width 7
Col2="FV_Cor" Char Width 7
Col3="FV_Nom" char Width 7
Col4="ADD" char Width 4
Col5="ADD_Ca" char Width 6
Col6="DI" Char Width 3
Col7="E" char Width 2
Col8="Lot_Number" char Width 12
Col9="Mar" char Width 4
Col10="Tin" char Width 4
Col11="SKU_Code" char Width 11
Col12="D_A_B" Char Width 6
Col13="Pad_X" char Width 6
Col14="Pad_Y" char Width 6
Col15="Pad_Z" char Width 6
Col16="MI_Tr" char Width 6
Col17="Check" char Width 6
Col18="Check_V" char Width 3
Col19="Quali" char Width 6
Col20="Quali_V" char Width 2
Col21="GR" char Width 3
Col22="Radius_CC" char Width 9
Col23="Index" char Width 7
Col24="CenTh" char width 6
Col25="Clic" char width 5
Col26="Bnom" char width 5
Col27="Pa" char width 3
Col28="Dpt_Cal" char width 8
Col29="ProX" char width 5
Col30="ProY" char width 5
Col31="GriX" char width 5
Col32="GriY" char width 5
Col33="CliX" char width 5
Col34="CliY" char width 5
Col35="ErrPro" char width 6
Col36="Suivi" char width 6
Col37="T_Tot" char width 6
Col38="T_Man" char width 6
Col39="Resea" char width 6
Col40="T_L" char width 4
Col41="T_P" char width 4
Col42="T_O" char width 4
Col43="TPC" char width 4
Col44="TQC" char width 4
Col45="T_" char width 4
Col46="TXY" char width 4
Col47="TRO" char width 4
Col48="_" char width 4
=============

If you can assist, it will be appreciated! This is an Schema.ini structure,
but, I'd like to change it into a looping function (placing data columns in
their respective places in the target table) since there may be multiple
files under various names that will need to be imported.
 

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

Similar Threads


Top