M
M
I have the following code:
Sub AppendFromTxt()
Dim lngI As Long
Dim strBuffer As String
Dim intFileNumber As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
intFileNumber = FreeFile
Open "C:\Temp.txt" For Input As #intFileNumber
'***Get rid of the first 5 lines
For lngI = 1 To 5
Line Input #intFileNumber, strBuffer
Next lngI
Do Until EOF(intFileNumber)
Line Input #intFileNumber, strBuffer
Set db = CurrentDb
Set rs = db.OpenRecordset("tblTemp")
With rs
Do Until .EOF
.AddNew
If IsNull(.Fields("Field1").Value)
Or .Fields("Field1").Value = "" Then
.Fields("Field1").Value = strBuffer
End If
.MoveNext
Loop
End With
Loop
Close #intFileNumber
End Sub
....that opens the textfile, eliminates the first five
lines as junk and attempts to insert the text into a temp
table. It loops through each line fine and strBuffer
changes with each loop. But it doesn't write to the
Recordset. I'm missing something very simple here. What is
it?!?
Thanks
M
Sub AppendFromTxt()
Dim lngI As Long
Dim strBuffer As String
Dim intFileNumber As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
intFileNumber = FreeFile
Open "C:\Temp.txt" For Input As #intFileNumber
'***Get rid of the first 5 lines
For lngI = 1 To 5
Line Input #intFileNumber, strBuffer
Next lngI
Do Until EOF(intFileNumber)
Line Input #intFileNumber, strBuffer
Set db = CurrentDb
Set rs = db.OpenRecordset("tblTemp")
With rs
Do Until .EOF
.AddNew
If IsNull(.Fields("Field1").Value)
Or .Fields("Field1").Value = "" Then
.Fields("Field1").Value = strBuffer
End If
.MoveNext
Loop
End With
Loop
Close #intFileNumber
End Sub
....that opens the textfile, eliminates the first five
lines as junk and attempts to insert the text into a temp
table. It loops through each line fine and strBuffer
changes with each loop. But it doesn't write to the
Recordset. I'm missing something very simple here. What is
it?!?
Thanks
M