Ben Kenobi
08-21-2002, 12:19 PM
Or, if you're Canadian, "hair grey" :D
Anyhow, when I run this, it gives me a "No current record" at the .Edit right after With t1. What am I missing?
Public Sub readcsv()
Dim i As Integer, l As Long, s As String, j As Integer, v As Long
Dim t1 As Recordset, t2 As Recordset, t3 As Recordset, t4 As Recordset
Open "biglonghairyfile.txt" For Input As #1
Set t1 = CurrentDb.TableDefs("BigTable1").OpenRecordset
Set t2 = CurrentDb.TableDefs("BigTable2").OpenRecordset
Set t3 = CurrentDb.TableDefs("BigTable3").OpenRecordset
Set t4 = CurrentDb.TableDefs("BigTable4").OpenRecordset
l = 1
Do While Not EOF(1)
Debug.Print l
Line Input #1, s
s = s & ","
t1.AddNew
t1!Field1 = 0
t1.Update
t2.AddNew
t2!Field256 = 0
t2.Update
t3.AddNew
t3!Field511 = 0
t3.Update
t4.AddNew
t4!Field766 = 0
t4.Update
For j = 1 To 885
i = InStr(1, s, ",")
v = Val("0" & Left(s, i - 1))
s = Mid(s, i + 1)
If j < 256 Then
With t1
.Edit
.Fields("Field" & j) = v
.Update
End With
ElseIf j < 511 Then
With t2
.Edit
.Fields("Field" & j) = v
.Update
End With
ElseIf j < 766 Then
With t3
.Edit
.Fields("Field" & j) = v
.Update
End With
Else
With t4
.Edit
.Fields("Field" & j) = v
.Update
End With
End If
Next j
l = l + 1
Loop
Close #1
End Sub
Anyhow, when I run this, it gives me a "No current record" at the .Edit right after With t1. What am I missing?
Public Sub readcsv()
Dim i As Integer, l As Long, s As String, j As Integer, v As Long
Dim t1 As Recordset, t2 As Recordset, t3 As Recordset, t4 As Recordset
Open "biglonghairyfile.txt" For Input As #1
Set t1 = CurrentDb.TableDefs("BigTable1").OpenRecordset
Set t2 = CurrentDb.TableDefs("BigTable2").OpenRecordset
Set t3 = CurrentDb.TableDefs("BigTable3").OpenRecordset
Set t4 = CurrentDb.TableDefs("BigTable4").OpenRecordset
l = 1
Do While Not EOF(1)
Debug.Print l
Line Input #1, s
s = s & ","
t1.AddNew
t1!Field1 = 0
t1.Update
t2.AddNew
t2!Field256 = 0
t2.Update
t3.AddNew
t3!Field511 = 0
t3.Update
t4.AddNew
t4!Field766 = 0
t4.Update
For j = 1 To 885
i = InStr(1, s, ",")
v = Val("0" & Left(s, i - 1))
s = Mid(s, i + 1)
If j < 256 Then
With t1
.Edit
.Fields("Field" & j) = v
.Update
End With
ElseIf j < 511 Then
With t2
.Edit
.Fields("Field" & j) = v
.Update
End With
ElseIf j < 766 Then
With t3
.Edit
.Fields("Field" & j) = v
.Update
End With
Else
With t4
.Edit
.Fields("Field" & j) = v
.Update
End With
End If
Next j
l = l + 1
Loop
Close #1
End Sub