rockfish12
Technical User
I've read thru some other tek-tips.com posts on how to programmatically import text files into a table in Access, and I came across some code (below) that I'm trying to make work:
When trying to run it, I experience an error on the "Line Input #1" line - the compiler tells me "variable required - can't assign to this expression."
The end goal here is to take a text file, read in each line, and assign it to a record...in effect, one line equals one record.
Is this code the right way to go about doing this? If so, what's wrong with my syntax? Or should I try something altogether different?
Code:
----------------------------------------
Sub ImportTarFiles(strFileName As String)
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.TableDefs("tblTAR").OpenRecordset
With rst
Open strFileName For Input As #1
Do While Not EOF(1)
.AddNew
Line Input #1, rst("filepath")
.Update
Wend
Close #1
End With
rst.Close
End Sub
----------------------------------------
The end goal here is to take a text file, read in each line, and assign it to a record...in effect, one line equals one record.
Is this code the right way to go about doing this? If so, what's wrong with my syntax? Or should I try something altogether different?