I am importing the rows of a CSV file into an Access table using the following code:
Set readingSet = CurrentDb.OpenRecordset("decibellog", dbOpenDynaset)
abortImport = False
fileHandle = FreeFile() ' Get the next available file handle.
lineImportCount = 0
Open fileSpec For Input As #fileHandle ' Open the decibel logger file.
While Not EOF(fileHandle) And Not abortImport ' While not at End-Of-File (EOF).
Line Input #fileHandle, fileLine ' Read a line from the decibel logger file.
lineArray = Split(fileLine, vbTab) ' Parse the line into an Array.
If lineArray(0) = "Place" Then
' Skip this header line.
Else
readingSet.AddNew ' Append a new record to the DecibelLog table.
readingSet!jobinstrumentimportid = jobInstImportId
readingSet!readingdate = DateValue(lineArray(1) & " " & lineArray(2))
readingSet!readingtime = lineArray(2)
readingSet!decibelreading = CDbl(lineArray(3))
readingSet!dbweighting = lineArray(4)
lineImportCount = lineImportCount + 1
End If
DoEvents ' Yield to operating system.
Wend
readingSet.Close ' Close the decibelreading dataset.
Set readingSet = Nothing
The
readingSet.AddNew
command does not add a new row to thedecibellog
table.No error is thrown.
The
RecordCount
property ofreadingSet
never increments. No rows are added to the table.Do I need to use a SQL INSERT instead of .AddNew?