That's the entirety of the file?
One row of ^ delimited values?
Or is are they bigger files with man rows of ^ delimited values?
do the files start with a line of data you want to import?
are there any lines you don't want to import?
the code really depends on how many of these files there are, if they have names that are identifiable by using some sort of string recognition etc.
Let's assume for the sake of argument that you have ONE file with three rows of data you want to import:
FILE NAME AND PATH = c:\Input.txt
Code:
RecordA^ValueAA^ValueBA
RecordB^ValueAB^ValueBB
RecordC^ValueAC^ValueBC
We'll assume there are no lines you want to ignore as well.
You want to import this into an access table called "Network_Stuff"
Assume your table Network_Stuff has this structure
ID (autonumber)
FirstField (text)
SecondField (text)
ThirdField text)
your code to add the records to the table would be something like:
Code:
Dim fInput
Dim fs
Dim sFileName
Dim LineArray
Dim sSeg
Dim db As Database
Dim sSQL As String
Set db = CurrentDb
Set fs = CreateObject("Scripting.filesystemobject")
sFileName = "c:\input.txt"
Set fInput = fs.opentextfile(sFileName)
Do While fInput.atendofstream <> True
sline = fInput.readline
'reads in a line from the text file
LineArray = Split(sline, "^")
'loads each portion of the string into an array
sSQL = "INSERT INTO Network_Stuff (FirstField,SecondField,ThirdField) VALUES ("
'start the ssql statment
For Each sSeg In LineArray
sSQL = sSQL & "'" & sSeg & "',"
'inserts the value and a comma for each item in the array assumes all fields are text
Next
sSQL = left(sSQL, Len(sSQL) - 1) & ")"
'removes the final comma on the string and puts in a closing paren
Debug.Print sSQL
db.Execute sSQL 'adds the record to the access table
Loop