Hi
I have below code where
after some records are being read in CSV file it goes to Do While Not EOF(file_number) but then jumps to rs.movenext instead of reading line of CSV.
What is missing here.
I have below code where
Code:
Sub compareCSV(filename As String, tablename As String, deletetablename As String)
Dim rs As DAO.Recordset
Dim file_number As Integer
Dim raw_line As String
Dim csv_line As Variant
Set DB = CurrentDb()
file_number = FreeFile
Open filename For Input As #file_number
Set rs = CurrentDb.OpenRecordset("SELECT * FROM " + tablename + "")
'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
RecordFound = False
field_value = rs![Unique ID]
Do While Not EOF(file_number)
Line Input #file_number, raw_line
csv_line = ProcessCsvData(raw_line)
field_index = 0
If UBound(csv_line) < field_index Then
' Guard against index out of bounds
ElseIf csv_line(field_index) = field_value Then
RecordFound = True
End If
Loop
rs.MoveNext
If RecordFound = False Then
DB.Execute "INSERT INTO " + deletetablename + " SELECT * FROM " + tablename + " where [UNIQUE ID] ='" + field_value + "'"
End If
Loop
Else
MsgBox "There are no records in the recordset."
End If
after some records are being read in CSV file it goes to Do While Not EOF(file_number) but then jumps to rs.movenext instead of reading line of CSV.
What is missing here.